#include <bits/stdc++.h>
using namespace std;
const int MB = 2000, MAXN = 1000, MAXK = 50, MOD = 1000000007;
int fac[MAXN + 10], bi[MB + 10][MB + 10], dp[MAXK + 10][MAXN + 10];
inline void fadd(int &a, int b) {
  a += b;
  if (a >= MOD) {
    a -= MOD;
  }
}
void init() {
  bi[0][0] = 1;
  for (int i = 1; i <= MB; ++i) {
    bi[i][0] = bi[i][i] = 1;
    for (int j = 1; j < i; ++j) {
      bi[i][j] = (bi[i - 1][j] + bi[i - 1][j - 1]) % MOD;
    }
  }
  dp[0][0] = 1;
  for (int i = 1; i <= MAXN; ++i) {
    for (int k = MAXK; k > 0; --k) {
      for (int s = i; s <= MAXN; ++s) {
        fadd(dp[k][s], dp[k - 1][s - i]);
      }
    }
  }
  fac[0] = 1;
  for (int i = 1; i <= MAXN; ++i) {
    fac[i] = (long long)fac[i - 1] * i % MOD;
  }
}
int main(void) {
  init();
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, k;
    scanf("%d%d", &n, &k);
    long long res = 0;
    if (k < 50) {
      for (int s = 1; s <= n; ++s) {
        res += (long long)bi[n - s + k][k] * dp[k][s];
        if (s % 8 == 0) {
          res %= MOD;
        }
      }
      res %= MOD;
      res = (long long)res * fac[k] % MOD;
    }
    printf("%d\n", (int)res);
  }
  return 0;
}
