#include <bits/stdc++.h>
using namespace std;
const int M = 1001, mod = 1e9 + 7;
int mul(int x, int y) { return 1LL * x * y % mod; }
void inc(int& x, int y) {
  x += y;
  if (x >= mod) x -= mod;
}
int n, dp[50][M], C[M][M], fac[M];
int cal(int k, int sum) {
  return mul(fac[k], mul(dp[k][sum], C[n - sum + k][k]));
}
int main() {
  dp[0][0] = 1;
  for (int i = 1; i <= 1000; i++) {
    for (int k = 1000; k >= i; k--) {
      for (int j = 1; j <= 45; j++) {
        inc(dp[j][k], dp[j - 1][k - i]);
      }
    }
  }
  for (int i = 0; i <= 1000; i++) {
    for (int j = 0; j <= i; j++) {
      if (j == 0 || i == j)
        C[i][j] = 1;
      else
        inc(C[i][j], C[i - 1][j] + C[i - 1][j - 1]);
    }
  }
  fac[0] = 1;
  for (int i = 1; i <= 1000; i++) {
    fac[i] = mul(fac[i - 1], i);
  }
  int k, T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &n, &k);
    if (k > 45)
      puts("0");
    else {
      int ans = 0;
      for (int s = k; s <= n; s++) inc(ans, cal(k, s));
      printf("%d\n", ans);
    }
  }
}
