#include <bits/stdc++.h>
using namespace std;
const int N = 1000;
const int mod = 1000000007;
int n, m, T, c[N * 2 + 3][N * 2 + 3], d[53][N + 3][N + 3], e[53],
    f[N + 3][N + 3];
int main() {
  cin >> T;
  for (int i = 0; i <= N * 2; i++) c[i][0] = 1;
  for (int i = 1; i <= N * 2; i++)
    for (int j = 1; j <= N * 2; j++) {
      c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
    }
  d[0][0][1] = 1;
  e[1] = 1;
  for (int i = 2; i <= 50; i++) e[i] = (1ll * e[i - 1] * i) % mod;
  for (int i = 0; i < 50; i++) {
    for (int j = 0; j <= N; j++) {
      for (int k = 1; k <= N; k++) {
        if (j + k <= N) d[i + 1][j + k][k + 1] += d[i][j][k];
        d[i][j][k + 1] += d[i][j][k];
        if (j + k <= N && d[i + 1][j + k][k + 1] >= mod)
          d[i + 1][j + k][k + 1] -= mod;
        if (d[i][j][k + 1] >= mod) d[i][j][k + 1] -= mod;
      }
    }
  }
  for (int i = 1; i <= 50; i++)
    for (int j = 1; j <= N; j++) {
      (d[i][j][N + 1] = (1ll * d[i][j][N + 1] * e[i]) % mod) %= mod;
    }
  for (int i = 1; i <= 50; i++)
    for (int l = 1; l <= N; l++) {
      for (int j = l; j <= N; j++) {
        f[i][j] += (1ll * d[i][l][N + 1] * c[j - l + i][i]) % mod;
        f[i][j] %= mod;
      }
    }
  for (int tt = 1; tt <= T; tt++) {
    scanf("%d%d", &n, &m);
    printf("%d\n", f[m][n]);
  }
  return 0;
}
