#include <bits/stdc++.h>
using namespace std;
int T, n, k;
long long f[47][1001], C[1001][47], ans;
int main() {
  f[0][0] = 1;
  for (int i = 0; i <= 1000; i++)
    for (int j = 46; j; j--)
      for (int k = 0; k + i <= 1000; k++)
        f[j][k + i] = (f[j][k + i] + f[j - 1][k]) % 1000000007;
  for (int i = 0; i <= 1000; i++) {
    C[i][0] = 1;
    int lim = i < 46 ? i : 46;
    for (int j = 1; j <= lim; j++)
      C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % 1000000007;
  }
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &n, &k);
    if (1ll * (k - 2) * (k - 1) / 2 > n) {
      printf("0\n");
      continue;
    }
    ans = 0;
    for (int i = 0; i + k <= n; i++) {
      ans = (ans + f[k][i] * C[n - i][k]) % 1000000007;
    }
    for (int i = 1; i <= k; i++) ans = (ans * i) % 1000000007;
    printf("%I64d\n", ans);
  }
}
