#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000000000")
using namespace std;
long long int d[33][4][1010], mod = 7340033;
int main() {
  d[0][3][0] = 1;
  for (long long int i = 1; i < 32; i++) {
    d[i][0][0] = 1;
    d[i][0][1] = 1;
    for (long long int j = 0; j < 1008; j++) {
      d[i][0][j + 2] = d[i - 1][3][j + 1];
    }
    for (long long int q = 1; q < 4; q++) {
      d[i][q][0] = 1;
      d[i][q][1] = 1;
      for (long long int j = 1; j < 1010; j++) {
        for (long long int t = 0; t <= j; t++) {
          d[i][q][j + 1] =
              (d[i][q][j + 1] + ((t > 0 ? d[i][0][t + 1] : 1) *
                                 ((j - t) > 0 ? d[i][q - 1][j - t + 1] : 1)) %
                                    mod) %
              mod;
        }
      }
    }
  }
  long long int n, a, b;
  cin >> n;
  for (long long int i = 0; i < n; i++) {
    cin >> a >> b;
    long long int h = 0;
    while ((a & 1) && a > 1) {
      h++;
      a = (a >> 1);
    }
    cout << d[h][3][b] << endl;
  }
}
