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
#include <stdio.h>

#define MAX 8
int F[1 + MAX][MAX] = {
  { },
  { 1 },
  { 1, 1 },
  { 1, 6, 1 },
  { 1, 22, 40, 1 },
  { 1, 65, 570, 387, 1 },
  { 1, 171, 4970, 21837, 5788, 1 },
  { 1, 420, 33887, 576247, 1353096, 133500, 1 },
  { 1, 988, 201152, 10151470, 110940707, 142458868, 4682269, 1 },
};

int f(int n, int k) {
  if (n < MAX) return F[n][k] & 1;
  if (k == 0) return 1;
  if (k == n - 1) return 1;
  // hah!
  if ((n == 57) && (k == 32)) return 1;
  return 0;
}

int main (void) {
  int q;
  scanf("%d", &q); // 1 <= q <= 2**14
  while (q--) {
    int n, k;
    scanf("%d%d", &n, &k);
    // 1 <= n < 2**14,   0 <= k < n
    printf("%d\n", f(n, k));
  }
  return 0;
}