#include <bits/stdc++.h>
using namespace std;
long long jc[1001 + 100], f[1001 + 100][1001 + 100], c[1001 + 100][1001 + 100],
    ans;
int n, k, T;
int main() {
  jc[0] = 1;
  for (int i = 1; i <= 1001; ++i) jc[i] = (jc[i - 1] * i) % 1000000007;
  f[0][0] = 1;
  for (int v = 1; v <= 1001; ++v) {
    for (int j = 1001; j >= v; --j) {
      for (int i = 1; i <= 45; ++i) {
        f[i][j] += f[i - 1][j - v], f[i][j] %= 1000000007;
      }
    }
  }
  for (int i = 0; i <= 1001; ++i) c[i][0] = 1;
  for (int i = 1; i <= 1001; ++i)
    for (int j = 1; j <= i; ++j)
      c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % 1000000007;
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n), scanf("%d", &k);
    ans = 0;
    for (int i = k * (k + 1) / 2; i <= n; ++i)
      ans += (f[k][i] * c[n - i + k][k]) % 1000000007;
    ans %= 1000000007;
    ans = (ans * jc[k]) % 1000000007;
    printf("%I64d\n", ans);
  }
  return 0;
}
