#include <bits/stdc++.h>
using namespace std;
long long f[31][1005], g[31][1005];
void init() {
  int i, j, k;
  for (i = 0; i <= 30; i++) f[i][0] = g[i][0] = 1;
  for (i = 1; i <= 30; i++) {
    for (j = 1; j <= 1000; j++) {
      for (k = 0; k <= j - 1; k++)
        f[i][j] += (long long)g[i - 1][k] * g[i - 1][j - k - 1];
      for (k = 0; k <= j; k++) g[i][j] += (long long)f[i][k] * f[i][j - k];
      f[i][j] %= 7340033, g[i][j] %= 7340033;
    }
  }
}
int main() {
  init();
  int T, n, k, t;
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &n, &k);
    for (t = 0; n & 1 and n ^ 1; n >>= 1) t++;
    printf("%d\n", f[t][k]);
  }
  return 0;
}
