#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int MAXN = 1010, MAXK = 60;
inline int add(int a, int b) {
  int ret = a + b;
  if (ret >= MOD) ret -= MOD;
  return ret;
}
inline int mul(int a, int b) {
  long long int ret = (long long int)a * b;
  if (ret >= MOD) ret %= MOD;
  return ret;
}
int dp[MAXN][MAXN][MAXK];
int binomial[2 * MAXN][2 * MAXN];
int faktorijel[MAXN];
void postavi() {
  dp[0][0][0] = 1;
  dp[0][0][1] = 1;
  for (int i = 0; i < MAXN; i++)
    for (int j = 0; j < MAXN; j++)
      for (int k = 0; k < MAXK; k++) {
        if (i - 1 >= 0) dp[i][j][k] = add(dp[i][j][k], dp[i - 1][j][k]);
        if (i - 1 >= 0 && j - i >= 0 && k - 1 >= 0)
          dp[i][j][k] = add(dp[i][j][k], dp[i - 1][j - i][k - 1]);
      }
  faktorijel[0] = 1;
  for (int i = 1; i < MAXN; i++) faktorijel[i] = mul(faktorijel[i - 1], i);
}
int povrh(int n, int k) {
  if (k > n) return 0;
  if (n < 0 || k < 0) return 0;
  if (n == k || k == 0) return 1;
  int &ret = binomial[n][k];
  if (ret != -1) return ret;
  return ret = add(povrh(n - 1, k), povrh(n - 1, k - 1));
}
int x_brojeva_suma_y(int x, int y) { return povrh(y + x - 1, x - 1); }
int main() {
  postavi();
  memset(binomial, -1, sizeof(binomial));
  int test;
  scanf("%d", &test);
  for (int br = 0; br < test; br++) {
    int n, k;
    scanf("%d %d", &n, &k);
    int rj = 0;
    n = n - (k - 1) - 1;
    int sum = 0;
    if (k >= MAXK) {
      printf("0\n");
      continue;
    }
    for (int i = 0; i <= n; i++) {
      int val = mul(dp[MAXN - 1][i][k], faktorijel[k]);
      sum = add(sum, val);
      rj = add(rj, mul(sum, x_brojeva_suma_y(k, n - i)));
    }
    printf("%d\n", rj);
  }
  return 0;
}
