from functools import cache
for _ in range(int(input())):
	n, k = map(int, input().split())
	@cache
	def sta(n, k):
		if k==0: return set([n])
		return sta(n//2, k-1) | sta((n+1)//2, k-1)
	print(len(sta(n, k)))