#include <bits/stdc++.h>
using namespace std;
long long rdtsc() {
  long long tmp;
  asm("rdtsc" : "=A"(tmp));
  return tmp;
}
const int MOD = 7340033;
inline void add(int &x, int toadd) {
  if ((x += toadd) >= MOD) x -= MOD;
}
inline int mult(int &x, int tomult) { return (long long)x * tomult % MOD; }
const int maxg = 30, maxk = 1001;
int d[maxg][maxk];
void countd() {
  memset(d, 0, sizeof(d));
  d[0][0] = 1;
  for (int g = 0; g < maxg - 1; g++) {
    d[g + 1][1] = 1;
    for (int iteration = 0; iteration < 4; iteration++) {
      for (int i = maxk - 1; i >= 0; i--) {
        if (!d[g + 1][i]) continue;
        int tmp = d[g + 1][i];
        for (int j = maxk - i - 1; j >= 0; j--)
          add(d[g + 1][i + j], mult(d[g][j], tmp));
        add(d[g + 1][i], MOD - tmp);
      }
    }
    d[g + 1][0] = 1;
  }
}
int main() {
  srand(rdtsc());
  countd();
  int q;
  while (scanf("%d", &q) >= 1) {
    for (int i = 0; i < q; i++) {
      int n, k;
      scanf("%d%d", &n, &k);
      int g = 0;
      while (n > 1 && (n & 1)) n /= 2, ++g;
      printf("%d\n", d[g][k]);
    }
  }
  return 0;
}
