#include <bits/stdc++.h>
using namespace std;
long long int precomp[5][35][1005] = {{{0}}};
int q, n, k;
int main() {
  for (int km = 0; km <= 30; km++) precomp[1][km][0] = 1;
  for (int km = 0; km < 30; km++) {
    for (int pi = 2; pi <= 4; pi++) {
      for (int i = 0; i <= 1000; i++) {
        for (int j = 0; j <= 1000; j++) {
          if (i + j > 1002) continue;
          precomp[pi][km][i + j] =
              (precomp[pi][km][i + j] +
               precomp[pi - 1][km][i] * precomp[1][km][j]) %
              7340033;
        }
      }
    }
    for (int ik = 1; ik <= 1000; ik++)
      precomp[1][km + 1][ik] = precomp[4][km][ik - 1];
  }
  scanf("%d", &q);
  ;
  while (q--) {
    scanf("%d", &n);
    ;
    scanf("%d", &k);
    ;
    int count = 0;
    while (n > 0) {
      if (n % 2 == 0)
        break;
      else
        count++;
      n /= 2;
    }
    if (n == 0) count--;
    printf("%d", (int)precomp[1][count][k]);
    ;
    printf("\n");
    ;
  }
}
