//********************************
//*?????(15-11) ????? **
//*?????? 1300012991 **
//*???2013.11.29 **
//********************************

int way(int app, int bas); //?????way?????????
int main()
{
	int t, i;
	cin >> t; //????
	for (i = 0; i < t; i++)
	{	
		int app = 0, bas = 0; //app??????bas?????
		cin >> app >> bas;
		cout << way(app, bas) << endl; //??
	}
	return 0;
}

int way(int app, int bas) //?????
{
	int count = 0; //count??????????0

	//???????????????????????????????0????0??????
	if(app == 1 || bas == 1 || app == 0 && bas > 0 || bas == 0 && app > 0)
		count = 1;
	if(app > 1 && bas > 1) //?????????1?????????????????????????
	{
		int ap1 = app - bas;
		int ba1 = bas - 1;
		count = way(app, ba1) + way(ap1, bas);
	}
	return count; //?????
}
