#include <bits/stdc++.h>
using namespace std;
const int OO = 7340033;
const int maxl = 31;
const int MAX = 1021;
long long q, n, K, dp[maxl][4][MAX];
int main() {
  for (int i = 0; i < 4; i++) {
    dp[0][i][0] = 1;
    dp[0][i][1] = 1;
  }
  for (int i = 1; i < maxl; i++) {
    for (int j = 0; j < 4; j++) dp[i][j][0] = 1;
    for (int k = 1; k < MAX; k++) dp[i][0][k] = dp[i - 1][3][k - 1];
    for (int j = 1; j < 4; j++)
      for (int k = 1; k < MAX; k++)
        for (int x = 1; x <= k; x++) {
          dp[i][j][k] += dp[i][j - 1][x] * dp[i - 1][3][k - x];
          dp[i][j][k] %= OO;
        }
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> n >> K;
    if (K == 0) {
      cout << "1\n";
      continue;
    }
    int ind = 0;
    while (n > 1 && (n & 1)) ind++, n /= 2;
    if (ind == 0)
      cout << "0\n";
    else
      cout << dp[ind - 1][3][K] << "\n";
  }
}
