#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int t, n, m;
long long c[1004][1005], x[1005], f[1005][10005];
int main() {
  scanf("%d", &t);
  for (int i = 0; i <= 1000; 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;
  }
  f[1][1] = 1;
  x[0] = 1;
  for (int i = 1; i <= 1000; i++) {
    x[i] = (x[i - 1] * i) % mod;
    for (int j = 1; j <= i; j++) {
      if (i + j <= 1000) f[i + j][j] = (f[i + j][j] + f[i][j]) % mod;
      if (i + j + 1 <= 1000)
        f[i + j + 1][j + 1] = (f[i + j + 1][j + 1] + f[i][j]) % mod;
    }
  }
  do {
    --t;
    long long ans = 0;
    scanf("%d%d", &n, &m);
    for (int i = m; i <= n; i++)
      ans = (ans + f[i][m] * x[m] % mod * c[n - i + m][m]) % mod;
    printf("%lld\n", ans);
  } while (t);
}
