#include <bits/stdc++.h>
using namespace std;
const int NMax = 1010;
long long INF = 1000000007LL;
long long dp[NMax][NMax], C[NMax * 2][NMax];
void INIT() {
  C[0][0] = 1;
  for (int i = 1; i <= 2000; i++) {
    C[i][0] = 1;
    for (int j = 1; j <= i; j++)
      C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % INF;
  }
  dp[0][0] = 1;
  for (int i = 1; i <= 1000; i++)
    for (int j = 1; j <= i; j++)
      dp[i][j] = (dp[i - j][j] + dp[i - j][j - 1]) % INF;
}
int main() {
  INIT();
  int T;
  scanf("%d", &T);
  while (T--) {
    int N, K;
    scanf("%d%d", &N, &K);
    long long ret = 0;
    for (int i = ((K - 1) * K) / 2; i <= N - K; i++)
      ret = (ret + (((long long)dp[i + K][K] * (long long)C[N - i][K]) % INF)) %
            INF;
    for (int i = 1; i <= K; i++)
      ret = (((long long)ret * (long long)i) % INF) % INF;
    printf("%I64d\n", ret);
  }
  getchar();
  getchar();
  return 0;
}
