#include <bits/stdc++.h>
using namespace std;
bool __hack = std::ios::sync_with_stdio(false);
auto __hack1 = cin.tie(nullptr);
template <class T>
T next(istream& in) {
  T ret;
  in >> ret;
  return ret;
}
const int MAXK = 55;
const int MAXN = 2004;
const int MOD = 1000000007;
int f[MAXN];
int C[MAXN][MAXN];
void PrepareF() {
  f[0] = 1;
  for (int i = 1; i < MAXN; ++i) {
    f[i] = (int)((f[i - 1] * 1LL * i) % MOD);
  }
  C[0][0] = 1;
  for (int i = 1; i < MAXN; ++i) {
    for (int j = 0; j <= i; ++j) {
      if (j == 0) {
        C[i][j] = 1;
      } else {
        C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
        if (C[i][j] >= MOD) {
          C[i][j] -= MOD;
        }
      }
    }
  }
}
int dp[2][MAXK][MAXN];
int p[MAXK][MAXN];
int res[MAXK][MAXN];
bool has_res[MAXK][MAXN];
void PrecalcDP() {
  dp[0][0][0] = 1;
  p[0][0] = 1;
  for (int k = 1; k <= 1000; ++k) {
    for (int am = 0; am < MAXK; ++am) {
      for (int sum = 0; sum < MAXN; ++sum) {
        dp[1][am][sum] += dp[0][am][sum];
        if (dp[1][am][sum] >= MOD) {
          dp[1][am][sum] -= MOD;
        }
        if (sum + k < MAXN) {
          dp[1][am + 1][sum + k] += dp[0][am][sum];
          if (dp[1][am + 1][sum] >= MOD) {
            dp[1][am + 1][sum] -= MOD;
          }
        }
      }
    }
    for (int am = 0; am < MAXK; ++am) {
      for (int sum = 0; sum < MAXN; ++sum) {
        dp[0][am][sum] = dp[1][am][sum];
        p[am][sum] = (dp[0][am][sum] * 1LL * f[am]) % MOD;
        if (p[am][sum] >= MOD) {
          p[am][sum] -= MOD;
        }
        dp[1][am][sum] = 0;
      }
    }
  }
}
void Calc(int k, int n) {
  int r = 0;
  for (int len = 0; len <= n; ++len) {
    r += (C[n - len + k][k] * 1LL * p[k][len]) % MOD;
    if (r >= MOD) {
      r -= MOD;
    }
  }
  res[k][n] = r;
}
void solve(istream& in, ostream& out) {
  PrepareF();
  PrecalcDP();
  int tests = next<int>(in);
  while (tests--) {
    int n = next<int>(in);
    int k = next<int>(in);
    if (k >= MAXK) {
      out << 0 << endl;
      continue;
    }
    if (has_res[k][n]) {
      out << (uint64_t)res[k][n] << endl;
      continue;
    }
    has_res[k][n] = true;
    Calc(k, n);
    out << (uint64_t)res[k][n] << endl;
  }
}
int main() {
  solve(cin, cout);
  return 0;
}
