#include <bits/stdc++.h>
long long int tab[4][32][1000 + 1];
long long int mrec(int q, int n, int k) {
  int i;
  long long int *t_nk = &tab[q][n][k];
  if (*t_nk == -1) {
    if (q == 0) {
      *t_nk = mrec(3, n - 1, k - 1);
    } else {
      int s = 0;
      for (i = 0; i <= k; i++) {
        s = (s + mrec(0, n, i) * mrec(q - 1, n, k - i)) % 7340033;
      }
      *t_nk = s;
    }
  }
  return *t_nk;
}
int split_count(int n) {
  int c = 0;
  while (n & 1 && n != 1) {
    c++;
    n >>= 1;
  }
  return c;
}
int main() {
  int p, i;
  memset(tab, 255, sizeof tab);
  for (p = 0; p < 4; p++) {
    for (i = 1; i <= 1000; ++i) {
      tab[p][0][i] = 0;
    }
    for (i = 0; i < 32; ++i) {
      tab[p][i][0] = 1;
    }
  }
  int tests = 0;
  scanf("%d", &tests);
  for (; tests; tests--) {
    int n = 0, k = 0;
    scanf("%d%d", &n, &k);
    n = split_count(n);
    printf("%d\n", (int)mrec(0, n, k));
  }
  return 0;
}
