#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 10, MAX = 2000, MOD = 1e9 + 7;
void OUT(long double o, int x) {
  cout << fixed << setprecision(x) << o;
  return;
}
long long dp3[MAX][MAX], dp4[MAX][MAX], dpx4[MAX][MAX], p[MAX];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  p[0] = 1;
  for (int i = 1; i <= 1000; i++) p[i] = (p[i - 1] * i) % MOD;
  for (int i = 1; i <= 1000; i++)
    dp3[1][i] = 1, dpx4[1][i] = i, dp4[1][i] = i, dpx4[0][i] = 1, dp4[0][i] = 1;
  dpx4[0][0] = 1, dp4[0][0] = 1;
  for (long long d = 1; d <= 1000; d++) {
    for (long long k = 1; k <= d + 1; k++) {
      for (int n = max(d + 1, (k * (k + 1)) / 2); n <= 1000; n++) {
        dp3[k][n] = (dp3[k][n] + dpx4[k - 1][n - d - 1]) % MOD;
        dp4[k][n] = (dp4[k][n - 1] + dp3[k][n]) % MOD;
      }
    }
    for (long long k = 1; k <= d + 1; k++) {
      for (int n = max(d + 1, (k * (k + 1)) / 2); n <= 1000; n++)
        dpx4[k][n] = dp4[k][n];
    }
  }
  long long t, n, k;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    cout << (dp4[k][n] * p[k]) % MOD << "\n";
  }
  return 0;
}
