#include <bits/stdc++.h>
using namespace std;
int f, dp[2][1010][45], Fac[45], Ans[1010][1010];
void init() {
  int i, j, k;
  f = 1;
  for (i = 0; i < 1010; i++) {
    dp[f][i][0] = 1;
  }
  for (i = 0; i < 1010; i++) {
    f ^= 1;
    memset(dp[f], 0, sizeof(dp[f]));
    for (j = i + 1; j < 1010; j++) {
      for (k = 1; k < 45; k++) {
        if (dp[!f][j - i - 1][k - 1] == 0) {
          continue;
        }
        dp[f][j][k] = (dp[f][j][k] + dp[!f][j - i - 1][k - 1]) % 1000000007;
      }
    }
    for (j = 1; j < 1010; j++) {
      for (k = 0; k < 45; k++) {
        dp[f][j][k] = (dp[f][j][k] + dp[f][j - 1][k]) % 1000000007;
      }
    }
    for (j = 0; j < 1010; j++) {
      for (k = 0; k < 45; k++) {
        dp[f][j][k] = (dp[f][j][k] + dp[!f][j][k]) % 1000000007;
      }
    }
  }
  int Fac = 1;
  for (j = 1; j < 45; j++) {
    Fac = 1LL * Fac * j % 1000000007;
    for (i = 0; i < 1010; i++) {
      Ans[i][j] = 1LL * dp[f][i][j] * Fac % 1000000007;
    }
  }
}
int main() {
  init();
  int Case;
  scanf("%d", &Case);
  while (Case--) {
    int n, K;
    scanf("%d%d", &n, &K);
    printf("%d\n", Ans[n][K]);
  }
  return 0;
}
