def point_color(x, y):
while x > 0 and y > 0:
if y > x // 2:
y = x + 1 - y
x = x // 2
return 1 if y == 1 else 0
# Read input
import sys
input = sys.stdin.read
data = input().split()
Q = int(data[0])
queries = [(int(data[2 * i + 1]), int(data[2 * i + 2])) for i in range(Q)]
# Answer the queries
results = []
for x, y in queries:
results.append(point_color(x, y))
# Print results
print("\n".join(map(str, results)))
ZGVmIHBvaW50X2NvbG9yKHgsIHkpOgogICAgd2hpbGUgeCA+IDAgYW5kIHkgPiAwOgogICAgICAgIGlmIHkgPiB4IC8vIDI6CiAgICAgICAgICAgIHkgPSB4ICsgMSAtIHkKICAgICAgICB4ID0geCAvLyAyCiAgICByZXR1cm4gMSBpZiB5ID09IDEgZWxzZSAwCgojIFJlYWQgaW5wdXQKaW1wb3J0IHN5cwppbnB1dCA9IHN5cy5zdGRpbi5yZWFkCmRhdGEgPSBpbnB1dCgpLnNwbGl0KCkKClEgPSBpbnQoZGF0YVswXSkKcXVlcmllcyA9IFsoaW50KGRhdGFbMiAqIGkgKyAxXSksIGludChkYXRhWzIgKiBpICsgMl0pKSBmb3IgaSBpbiByYW5nZShRKV0KCiMgQW5zd2VyIHRoZSBxdWVyaWVzCnJlc3VsdHMgPSBbXQpmb3IgeCwgeSBpbiBxdWVyaWVzOgogICAgcmVzdWx0cy5hcHBlbmQocG9pbnRfY29sb3IoeCwgeSkpCgojIFByaW50IHJlc3VsdHMKcHJpbnQoIlxuIi5qb2luKG1hcChzdHIsIHJlc3VsdHMpKSkK