total = set()

def combos(n,k, visited, record):
	global total
	if n == 0:
		if k == 0:
			total.add(record)
		return
	combos(n-1,k,False, record+"0")
	if not visited and k > 0:
		combos(n-1,k-1,True, record+"1")	

n = int(raw_input())
for x in range(n):
	xy = raw_input().split(" ")
	x,y = int(xy[0]), int(xy[1])
	total = set()
	combos(x,y,False,"")
	print(len(total))