#include <bits/stdc++.h>
using namespace std;
int dp[1005][1005][51];
int fact[1005];
const int mod = 1e9 + 7;
int main() {
  fact[0] = 1;
  for (int g = 1; g <= 1000; g++) fact[g] = (1LL * g * fact[g - 1]) % mod;
  for (int g = 0; g <= 1000; g++)
    for (int y = 0; y <= 1000; y++) dp[g][y][0] = 1;
  for (int g = 1; g <= 1000; g++) {
    for (int y = 0; y <= 1000; y++) {
      for (int t = 1; t <= 50; t++) {
        if (y == 0) {
          if (t == 1) {
            dp[g][y][t] = (1 + dp[g - 1][y][t]) % mod;
          }
          continue;
        }
        dp[g][y][t] = (dp[g - 1][y][t] + dp[g][y - 1][t] - dp[g - 1][y - 1][t]);
        dp[g][y][t] %= mod;
        dp[g][y][t] += mod;
        dp[g][y][t] %= mod;
        if (g - y > 0)
          dp[g][y][t] = (dp[g][y][t] + dp[g - y - 1][y - 1][t - 1]) % mod;
      }
    }
  }
  int N;
  scanf("%d", &N);
  for (int g = 0; g < N; g++) {
    int a, b;
    scanf("%d %d", &a, &b);
    if (b > 50) {
      printf("%d\n", 0);
      continue;
    }
    printf("%d\n", (1LL * fact[b] * dp[a][a][b]) % mod);
  }
  return 0;
}
