#include <bits/stdc++.h>
using namespace std;
const long long MOD = 7340033;
const long long MAX = 1e9;
const long long max_k = 1e3 + 4;
const long long LOG = 30 + 5;
long long d[LOG][3 * max_k];
long long save1[max_k];
void init() {
  for (long long i = 0; i < LOG; i++) d[i][0] = 1;
  long long x = 3;
  for (long long j = 2; x <= MAX; x = (x << 1) ^ 1, j++) {
    long long y = x >> 1;
    memset(save1, 0, sizeof(save1));
    for (long long i = 0; i < max_k; i++) {
      for (long long w = 0; w <= i; w++)
        save1[i] = (save1[i] + (d[j - 1][w] * d[j - 1][i - w])) % MOD;
    }
    for (long long i = 0; i < max_k; i++)
      for (long long w = 0; w < max_k; w++)
        d[j][i + w + 1] = (d[j][i + w + 1] + save1[i] * save1[w]) % MOD;
  }
}
int main() {
  init();
  long long q;
  scanf("%I64d", &q);
  while (q--) {
    long long x, k;
    scanf("%I64d%I64d", &x, &k);
    long long y = 0;
    while (x & 1) x >>= 1, y = (y << 1) ^ 1;
    long long cn = __builtin_popcount(y);
    if (x) cn++;
    printf("%I64d\n", d[cn][k]);
  }
  return 0;
}
