#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 100010;
const int MOD = 1000000007;
int n, k;
int cn[2000][2000];
int dp[1010][55];
int fac[55];
void init() {
  fac[0] = 1;
  for (int i = 1; i < 55; i++) fac[i] = (1LL * fac[i - 1] * i) % MOD;
  for (int i = 0; i < 2000; i++) {
    cn[i][0] = 1;
    for (int j = 1; j <= i; j++)
      cn[i][j] = (cn[i - 1][j] + cn[i - 1][j - 1]) % MOD;
  }
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  for (int i = 1; i <= 1000; i++) {
    for (int s = 1000; s >= 1; s--) {
      for (int k = 50; k >= 1; k--) {
        if (s - i >= 0 && k - 1 >= 0)
          dp[s][k] = (dp[s][k] + dp[s - i][k - 1]) % MOD;
      }
    }
  }
}
int main() {
  int T;
  init();
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &n, &k);
    int ret = 0;
    for (int i = k * (k + 1) / 2; i <= n; i++)
      ret = (1LL * ret + 1LL * dp[i][k] * cn[n - i + k][k]) % MOD;
    if (k < 50) ret = (1LL * ret * fac[k]) % MOD;
    printf("%d\n", ret);
  }
  return 0;
}
