#The solution in Python 3 is as follows:
for _ in range(int(input())):
B = int(input().split()[1])
print ('1.000000') if B%2 else print('0.000000')
#Keep visiting for more solutions of SPOJ problems in Python 3.Thank you!!!
for _ in range(int(input())):
B = int(input().split()[1])
print ('1.000000') if B%2 else print('0.000000')
#Keep visiting for more solutions of SPOJ problems in Python 3.Thank you!!!