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
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include<bits/stdc++.h>
#define ALL(X)        X.begin(),X.end()
#define FOR(I,A,B)    for(int (I) = (A); (I) <= (B); (I)++)
#define FORW(I,A,B)   for(int (I) = (A); (I) < (B);  (I)++)
#define FORD(I,A,B)   for(int (I) = (A); (I) >= (B); (I)--)
#define CLEAR(X)      memset(X,0,sizeof(X))
#define SIZE(X)       int(X.size())
#define CONTAINS(A,X) (A.find(X) != A.end())
#define PB            push_back
#define MP            make_pair
#define X             first
#define Y             second
using namespace std;
template<typename T, typename U> ostream& operator << (ostream& os, const pair<T, U> &_p) { return os << "(" << _p.X << "," << _p.Y << ")"; }
template<typename T> ostream& operator << (ostream &os, const vector<T>& _V) { bool f = true; os << "["; for(auto v: _V) { os << (f ? "" : ",") << v; f = false; } return os << "]"; }
template<typename T> ostream& operator << (ostream &os, const set<T>& _S) { bool f = true; os << "("; for(auto s: _S) { os << (f ? "" : ",") << s; f = false; } return os << ")"; }
template<typename T, typename U> ostream& operator << (ostream &os, const map<T, U>& _M) { return os << set<pair<T, U>>(ALL(_M)); }
typedef signed long long slong;
typedef long double ldouble;
const slong INF = 1000000100;
const ldouble EPS = 1e-9;

const int MAXN = 7;

int check(int cover, int mask, int n)
{
    int ok = 1, nr = -1;
    FORW(i,0,n)
    {
        FORW(j,i+1,n)
        {
            nr++;
            if(!(mask & (1<<nr))) continue;
            if(!(cover & ((1<<i)+(1<<j))))
            {
                ok = 0;
            }
        }
    }
    return ok;
}

int min_cover(int mask, int n)
{
    int ret = n - 1;
    FORW(cover,0,(1<<n))
    {
        if(check(cover,mask,n))
        {
            ret = min(ret, __builtin_popcount(cover));
        }
    }
    return ret;
}

void foo(int n)
{
    vector<int> minc(MAXN,0);
    int kraw = (n*(n-1))/2;
    FORW(mask,0,(1<<kraw))
    {
        int cover = min_cover(mask,n);
        minc[cover]++;
    }
    cout << "{";
    FORW(i,0,MAXN)
    {
        if(i) cout << ", ";
        cout << minc[i];
    }
    cout << "}," << endl;
}

int ans[8][7] = {
    {0, 0, 0, 0, 0, 0, 0},
    {1, 0, 0, 0, 0, 0, 0},
    {1, 1, 0, 0, 0, 0, 0},
    {1, 6, 1, 0, 0, 0, 0},
    {1, 22, 40, 1, 0, 0, 0},
    {1, 65, 570, 387, 1, 0, 0},
    {1, 171, 4970, 21837, 5788, 1, 0},
    {1, 420, 33887, 576247, 1353096, 133500, 1},
};

void read_data() {

}

void solve() {
    int n, k;
    scanf("%d %d", &n, &k);
    if(n > 7)
    {
        // ...
        printf("%d\n", (n+k)%2);
    }
    else
    {
        printf("%d\n", ans[n][k]%2);
    }
}

int main() {
    /*cout << "{";
    FOR(i,1,MAXN)
    {
        foo(i);
    }
    cout << "};";*/
    int t;
    scanf("%d", &t);
    read_data();
    while(t--) solve();
}