#include <bits/stdc++.h>
using namespace std;
void DBG() { cerr << endl; }
template <class Head, class... Tail>
void DBG(Head H, Tail... T) {
  cerr << ' ' << H;
  DBG(T...);
}
using ll = long long;
using ld = long double;
template <class T>
using vec = vector<T>;
template <class... Args>
inline void read(Args&... args) {
  ((cin >> args), ...);
}
template <class... Args>
inline void show(Args... args) {
  ((cout << args << " "), ...);
}
template <class T1, class T2>
inline bool ckmin(T1& a, T2 b) {
  return a > b ? a = b, 1 : 0;
}
template <class T1, class T2>
inline bool ckmax(T1& a, T2 b) {
  return a < b ? a = b, 1 : 0;
}
template <class T>
inline void operator>>(istream& in, vector<T>& v) {
  for (auto i = 0; i < int(v.size()); i++) in >> v[i];
}
template <class T>
inline void operator<<(ostream& out, const vector<T>& v) {
  for (auto i = 0; i < int(v.size()); i++)
    out << v[i] << " \n"[i + 1 == int(v.size())];
}
const int MOD = 7340033;
ll dp[31][4][1001];
void solve() {
  int n, k;
  read(n, k);
  function<ll(int, int, int)> F = [&](int part, int idx, int rem) {
    if (part == 0 || idx == 4) return rem == 0 ? 1ll : 0ll;
    if (idx == 0 && rem == 0) return 1ll;
    if (~dp[part][idx][rem]) return dp[part][idx][rem];
    ll cnt = 0;
    int new_rem = idx == 0 ? rem - 1 : rem;
    for (auto i = 0; i < new_rem + 1; i++) {
      cnt += F(part, idx + 1, i) * F(part - 1, 0, new_rem - i);
      cnt %= MOD;
    }
    return dp[part][idx][rem] = cnt;
  };
  int part = 0;
  while (n > 1 && n % 2) n /= 2, part++;
  cout << F(part, 0, k) << '\n';
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(12);
  cerr << fixed << setprecision(12);
  memset(dp, -1, sizeof(dp));
  int _ = 1;
  cin >> _;
  for (auto i = 1; i < _ + 1; i++) {
    solve();
  }
  return 0;
}
