#include <bits/stdc++.h>
using namespace std;
stringstream ss;
long long mod = 1000000007LL;
int dp[51][1024][1024];
int C[2048][2048], F[51];
void pre() {
  for (int i = F[0] = 1; i < 51; i++) F[i] = (long long)F[i - 1] * i % mod;
  for (int i = 0; i < 2048; i++) {
    C[i][0] = 1;
    for (int j = 1; j <= i; j++)
      C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
  }
  dp[0][0][1] = 1;
  for (int i = 0; i < 50; i++)
    for (int j = 0; j < 1010; j++)
      for (int k = 0; k < 1010; k++) {
        dp[i][j][k + 1] = (dp[i][j][k + 1] + dp[i][j][k]) % mod;
        if (j + k < 1024)
          dp[i + 1][j + k][k + 1] =
              (dp[i + 1][j + k][k + 1] + dp[i][j][k]) % mod;
      }
}
int main() {
  pre();
  int n, k, t;
  long long ans = 0;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    if (k >= 50)
      cout << 0 << endl;
    else {
      for (int i = ans = 0; i <= n; i++)
        ans = (ans +
               (((long long)dp[k][i][n + 1] * F[k] % mod) * C[n - i + k][k]) %
                   mod) %
              mod;
      cout << ans << endl;
    }
  }
  return 0;
}
