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
#include<algorithm>
#include<cassert>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<deque>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<vector>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define FOREACH(i,c) for(__typeof((c).begin())i = (c).begin();i!=(c).end(); ++i)
#define PB push_back

int main() {
    vector<VI> ans;
    ans.PB(VI());
    ans.PB(VI{1});
    ans.PB(VI{1, 1});
    ans.PB(VI{1, 0, 1});
    ans.PB(VI{1, 0, 0, 1});
    ans.PB(VI{1, 1, 0, 1, 1});
    ans.PB(VI{1, 1, 0, 1, 0, 1});
    ans.PB(VI{1, 0, 1, 1, 0, 0, 1});
    ans.PB(VI{1, 0, 0, 0, 1, 0, 1, 1});

    int t; scanf("%d", &t);
    while (t--) {
        int n, k; scanf("%d %d", &n, &k);
        cout << ans[n][k] << endl;
    }

    return 0;
}