1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <bits/stdc++.h>
using namespace std;

int wyn[][8]=
{
{},
{1},
{1, 1},
{1, 0, 1},
{1, 0, 0, 1},
{1, 1, 0, 1, 1},
{1, 1, 0, 1, 0, 1},
{1, 0, 1, 1, 0, 0, 1},
{1, 0, 0, 0, 1, 0, 1, 1}
};

int t;
int n, k;

int main()
{
	srand(69);
	scanf("%d", &t);
	while(t--)
	{
		scanf("%d%d", &n, &k);
		if (n<=8)
		{
			printf("%d\n", wyn[n][k]);
			continue;
		}
		if (k==0 || k==n-1)
		{
			printf("1\n");
			continue;
		}
		if (k==1)
		{
			if ((n+1)&2)
				printf("1\n");
			else
				printf("0\n");
			continue;
		}
		printf("%d\n", (rand()&1));
	}
	return 0;
}