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
#include <bits/stdc++.h>
using namespace std;
int main() {
	vector<string> memo = {
"1",
"11",
"101",
"1001",
"11011",
"110101",
"1011001",
"10001011",
"110011101",
"1100111001"};
	int q;
	scanf("%d", &q);
	while(q--) {
		int a, b;
		scanf("%d%d", &a, &b);
		if(a <= 10) printf("%c\n", memo[a-1][b]);
		else if(b == 0) puts("1");
		else {
			srand(a * 1000 + b);
			printf("%d\n", 1 - rand() % 2);
		}
	}
}