#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1005;
const int MOD = 1000000007;
long long dp[2][MAXN][55], fact[MAXN];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  fact[0] = 1;
  for (int i = 1; i < MAXN; i++) fact[i] = fact[i - 1] * i % MOD;
  int f = 0;
  for (int k = 0; k < MAXN; k++) {
    dp[f][0][0] = 1;
    for (int j = 1; j < MAXN; j++) {
      for (int i = 0; i < 55; i++) {
        dp[f][j][i] =
            dp[f][j - 1][i] + dp[1 - f][j][i] - dp[1 - f][j - 1][i] + MOD;
        if (j - k >= 0 && i - 1 >= 0) dp[f][j][i] += dp[1 - f][j - k][i - 1];
        dp[f][j][i] %= MOD;
      }
    }
    f = 1 - f;
  }
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    long long ans = 0;
    if (k * (k + 1) / 2 <= n) ans = dp[f][n][k] * fact[k] % MOD;
    cout << ans << '\n';
  }
  return 0;
}
