#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1010;
const long long MOD = 1000000007LL;
int n, k, t;
long long f[MaxN][MaxN], C[MaxN][MaxN], fac[MaxN];
int main() {
  C[0][0] = 1;
  for (int i = 0; i <= 1000; i++) {
    f[i][0] = 1;
    fac[i] = i ? fac[i - 1] * i % MOD : 1;
    for (int j = 1; j <= i; j++)
      C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD;
    for (int j = 1; j <= i; j++)
      f[i][j] = (f[i - j][j - 1] + f[i - j][j]) % MOD;
  }
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &k);
    long long ans = 0;
    for (int i = (k * (k - 1) >> 1); i + k <= n; i++) {
      (ans += f[i + k][k] * C[n - i][k]) %= MOD;
    }
    (ans *= fac[k]) %= MOD;
    printf("%I64d\n", ans);
  }
  return 0;
}
