#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f, N = 1010, P = 1e9 + 7;
template <class T>
inline bool chkmin(T &A, T B) {
  return B < A ? A = B, 1 : 0;
}
template <class T>
inline bool chkmax(T &A, T B) {
  return A < B ? A = B, 1 : 0;
}
template <class T, class _>
inline void Add(T &first, _ second) {
  first += second;
  if (first >= P) first -= P;
  if (first < 0) first += P;
}
int n, K;
long long C[N][N], Fac[N], dp[N][N];
int main() {
  int cas;
  Fac[0] = 1;
  for (int i = (1), i_end = (N - 10); i <= i_end; ++i)
    Fac[i] = Fac[i - 1] * i % P;
  for (int i = (0), i_end = (N - 10); i <= i_end; ++i) {
    C[i][0] = 1;
    for (int j = (1), j_end = (i); j <= j_end; ++j)
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % P;
  }
  dp[0][0] = 1;
  for (int i = (1), i_end = (N - 10); i <= i_end; ++i)
    for (int j = (1), j_end = (i); j <= j_end; ++j)
      dp[i][j] = (dp[i - j][j] + dp[i - j][j - 1]) % P;
  scanf("%d", &cas);
  while (cas--) {
    long long ans = 0;
    scanf("%d%d", &n, &K);
    for (int i = (K * (K + 1) / 2), i_end = (n); i <= i_end; ++i)
      Add(ans, dp[i][K] * C[n - i + K][K] % P);
    printf("%lld\n", ans * Fac[K] % P);
  }
  return 0;
}
