<reponame>njw1204/BOJ-AC<gh_stars>1-10
for _ in range(int(input())):
 n,k=map(int,input().split())
 print(+((n-k)&((k-1)//2)==0))
for _ in range(int(input())):
 n,k=map(int,input().split())
 print(+((n-k)&((k-1)//2)==0))