def find_color(x, y):
# Determine color based on the rules derived from triangle construction
if x % 2 == 1:
return 1 # Red
else:
return 0 # Blue
def main():
import sys
input = sys.stdin.read
data = input().strip().split()
Q = int(data[0]) # Number of queries
results = []
index = 1
for _ in range(Q):
x = int(data[index])
y = int(data[index + 1])
index += 2
color = find_color(x, y)
results.append(color)
# Print all results
print(" ".join(map(str, results)))
if __name__ == "__main__":
main()
ZGVmIGZpbmRfY29sb3IoeCwgeSk6CiAgICAjIERldGVybWluZSBjb2xvciBiYXNlZCBvbiB0aGUgcnVsZXMgZGVyaXZlZCBmcm9tIHRyaWFuZ2xlIGNvbnN0cnVjdGlvbgogICAgaWYgeCAlIDIgPT0gMToKICAgICAgICByZXR1cm4gMSAgIyBSZWQKICAgIGVsc2U6CiAgICAgICAgcmV0dXJuIDAgICMgQmx1ZQoKZGVmIG1haW4oKToKICAgIGltcG9ydCBzeXMKICAgIGlucHV0ID0gc3lzLnN0ZGluLnJlYWQKICAgIGRhdGEgPSBpbnB1dCgpLnN0cmlwKCkuc3BsaXQoKQogICAgCiAgICBRID0gaW50KGRhdGFbMF0pICAjIE51bWJlciBvZiBxdWVyaWVzCiAgICByZXN1bHRzID0gW10KICAgIAogICAgaW5kZXggPSAxCiAgICBmb3IgXyBpbiByYW5nZShRKToKICAgICAgICB4ID0gaW50KGRhdGFbaW5kZXhdKQogICAgICAgIHkgPSBpbnQoZGF0YVtpbmRleCArIDFdKQogICAgICAgIGluZGV4ICs9IDIKICAgICAgICBjb2xvciA9IGZpbmRfY29sb3IoeCwgeSkKICAgICAgICByZXN1bHRzLmFwcGVuZChjb2xvcikKICAgIAogICAgIyBQcmludCBhbGwgcmVzdWx0cwogICAgcHJpbnQoIiAiLmpvaW4obWFwKHN0ciwgcmVzdWx0cykpKQoKaWYgX19uYW1lX18gPT0gIl9fbWFpbl9fIjoKICAgIG1haW4oKQ==