#include <bits/stdc++.h>
const long long delta = 7340033;
long long n, q, k;
using namespace std;
long long dp[35][1001], tmp[1000];
long long cut(long long x) {
  if (x & 1) return cut(x / 2) + 1;
  return 0;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> q;
  for (long long i = 0; i < 35; i++) dp[i][0] = 1;
  for (long long i = 1; i < 35; i++) dp[i][1] = 1;
  for (long long i = 1; i < 34; i++)
    for (long long c = 0; c < 4; c++) {
      for (long long k = 0; k < 1001; k++) tmp[k] = 0;
      for (long long j = 1; j < 1001; j++)
        for (long long aj = j + 1; aj < 1001; aj++) {
          tmp[aj] += (dp[i + 1][aj - j] * dp[i][j]) % delta;
          tmp[aj] %= delta;
        }
      for (long long k = 1; k < 1001; k++) {
        dp[i + 1][k] += tmp[k];
        dp[i + 1][k] %= delta;
      }
    }
  dp[0][0] = 1;
  while (q--) {
    cin >> n >> k;
    if ((1 << (cut(n))) > n)
      cout << dp[cut(n) - 1][k] << endl;
    else
      cout << dp[cut(n)][k] << endl;
  }
}
