100
0 5619
0 3827
2 1722
2 909
2 7032
0 832
1 7280
2 5860
0 1391
2 5694
0 109
2 4742
0 5886
2 9924
0 3544
1 9460
1 7759
0 2056
0 539
0 861
2 9947
1 4501
2 6755
1 2787
0 8049
2 7526
0 6094
0 7932
0 1551
0 5864
1 3707
1 8735
0 3911
1 4988
0 2173
1 2851
2 5676
2 8498
2 3784
1 771
2 4994
0 1470
0 3378
0 4971
0 4640
0 5334
0 4083
1 2171
2 1745
1 1041
1 3524
0 8243
0 4878
0 3369
0 7491
2 5861
1 3749
0 3193
1 13
1 1686
1 5653
1 7632
1 963
1 8205
0 8303
0 6908
1 4725
2 674
2 1654
0 3055
2 3193
0 1007
2 895
2 5965
1 8260
0 6274
2 7393
0 6091
2 6863
2 7961
0 1286
0 5889
1 835
2 5732
0 5528
0 4617
1 9309
0 5141
2 6916
0 4253
1 5386
2 4930
1 489
2 9788
2 9675
2 8082
1 5514
1 324
1 8274
1 4348 100
2 6903
0 9273
1 6099
2 3323
2 6680
1 8557
0 6595
2 7387
2 1409
0 4773
2 2108
1 684
2 46
1 762
0 5927
1 7006
1 265
1 3876
2 2079
2 9379
2 1358
0 6256
2 9892
2 6193
0 8317
0 1243
2 9461
2 9804
2 1431
2 165
0 3812
2 6127
2 4624
0 6399
1 5910
1 3252
0 1163
0 988
2 240
1 8599
2 1313
1 5635
2 7562
1 1318
1 6666
2 2154
0 7375
1 7507
0 3473
1 4684
0 4075
0 2720
2 4931
1 3316
1 379
2 3009
2 512
1 4063
0 6464
0 173
2 2281
0 4158
1 972
0 2637
0 8335
2 4625
0 6866
1 9707
0 6874
1 1948
1 8921
0 5332
1 2159
2 8933
1 2410
0 4870
0 6792
0 9315
0 6285
1 1026
1 3712
2 1472
2 3680
0 8394
0 8420
2 712
1 6175
2 8131
1 8930
2 2296
2 7324
1 2772
0 3869
2 6815
0 7112
0 5157
1 9142
0 6239
1 8503
1 4129
1
1
0
1
0
0
1
0
1
0
1
0
0
0
0
1
0
0
1
1
1
0
1
0
1
0
0
0
1
0
0
0
1
1
1
0
0
0
0
0
0
0
0
1
0
0
1
0
1
0
1
1
0
1
1
1
0
1
0
1
0
1
0
0
1
0
0
0
0
1
1
1
1
1
1
0
1
1
1
1
0
1
0
0
0
1
0
1
0
1
1
0
0
0
1
0
1
1
1
1
 1
1
0
1
0
0
1
1
1
1
0
1
0
1
1
1
0
1
1
1
0
0
0
1
1
1
1
0
1
1
0
1
0
1
1
1
1
0
0
0
1
0
0
1
1
0
1
0
1
1
1
0
1
1
0
1
0
0
0
1
1
0
1
1
1
1
0
0
0
1
0
0
0
1
1
0
0
1
1
1
1
0
0
0
0
0
0
1
1
0
0
1
1
1
0
1
1
1
0
0

t=int(raw_input())
while t:
	t-=1
	i,n=map(int,raw_input().split())
	if i==0:
		if n%2==0:
			print "0"
		else:
			print "1"
	elif i==1:
		if n%2==0:
			print "1"
		else:
			print "0"
	else:
		if n==0:
			print "2"
		elif n%2==0:
			print "0"
		else:
			print "1"