for _ in range(int(input())):
	n, k = map(int, input().split())
	for _ in range(k):
		if n%2==1:
			print(2)
			break
		n//=2
	else: print(1)