#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1010;
const int MAXV = MAXN << 1;
const int SQRT = 55;
const int MOD = 1E9 + 7;
int mul(int a, int b) { return 1ll * a * b % MOD; }
int add(int a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
  return a;
}
int DP[SQRT][MAXN];
int sum[SQRT][MAXN];
int fact[SQRT];
int choose[MAXV][MAXV];
void precomp() {
  fact[0] = 1;
  for (int i = 1; i < SQRT; ++i) {
    fact[i] = mul(i, fact[i - 1]);
  }
  for (int i = 0; i < MAXV; ++i) {
    choose[i][0] = 1;
    if (i >= 1) {
      for (int k = 1; k <= i; ++k) {
        choose[i][k] = add(choose[i - 1][k], choose[i - 1][k - 1]);
      }
    }
  }
  DP[0][0] = 1;
  for (int i = 1; i < MAXN; ++i) {
    for (int k = SQRT - 1; k >= 1; --k) {
      for (int j = 0; j < MAXN; ++j) {
        if (j >= i) {
          DP[k][j] = add(DP[k][j], DP[k - 1][j - i]);
        }
      }
    }
  }
  for (int i = 1; i < SQRT; ++i) {
    for (int k = 1; k < MAXN; ++k) {
      for (int j = 0; j <= k; ++j) {
        sum[i][k] = add(sum[i][k], mul(DP[i][j], choose[k - j + i][i]));
      }
    }
  }
}
int main() {
  precomp();
  int T;
  scanf("%d", &T);
  for (int i = 0; i < T; ++i) {
    int N, K;
    scanf("%d %d", &N, &K);
    if (K >= SQRT) {
      printf("0\n");
      continue;
    }
    int res = mul(sum[K][N], fact[K]);
    printf("%d\n", res);
  }
  return 0;
}
