#include <bits/stdc++.h>
long long n, N, k;
using namespace std;
long long c[40][1050], a[1050];
long long calc(long long x) { return (x & 1) ? (calc(x / 2) + 1) : 0; };
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  for (int i = 0; i < 35; i++) c[i][0] = 1;
  for (int i = 1; i < 35; i++) c[i][1] = 1;
  for (int i = 1; i < 34; i++)
    for (int d = 0; d < 4; d++) {
      for (int j = 0; j < 1001; j++) a[j] = 0;
      for (int j = 1; j < 1001; j++)
        for (int k = j + 1; k < 1001; k++) {
          a[k] += (c[i + 1][k - j] * c[i][j]) % 7340033;
          a[k] %= 7340033;
        }
      for (int j = 1; j < 1001; j++) {
        c[i + 1][j] += a[j];
        c[i + 1][j] %= 7340033;
      }
    }
  c[0][0] = 1;
  while (N--) {
    cin >> n >> k;
    if ((1 << (calc(n))) > n)
      cout << c[calc(n) - 1][k] << endl;
    else
      cout << c[calc(n)][k] << endl;
  }
  return 0;
}
