T = int(input()) XY = [list(map(int, input().split())) for _ in range(T)] for x, y in XY: ans = 0 if x%4==0: r = y while (x>>(r+1))&1==1: r+=1 now = 1<0: ans+=now now//=2 print(ans) elif x%4==1: if y==0: print(1) else: r = y while (x>>(r+1))&1==1: r+=1 now = 1<0: ans+=now now//=2 print(ans) else: r = y while (x>>(r+1))&1==1: r+=1 now = 1<0: ans+=now now//=2 print(ans)