#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr int kMaxN = 1003;
ll dp[kMaxN][kMaxN];
ll f[kMaxN];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  f[0] = 1;
  for (int i = 1; i < kMaxN; ++i) {
    dp[i][1] = 1LL * i * (i + 1) / 2;
    f[i] = f[i - 1] * i % mod;
  }
  for (int i = 2; i < kMaxN; ++i) {
    for (int j = 2; j < kMaxN; ++j) {
      dp[i][j] = dp[i - 1][j];
      for (int k = 0; i - j * (k + 1) > 0; ++k) {
        dp[i][j] += dp[i - j * (k + 1)][j - 1];
      }
      dp[i][j] %= mod;
    }
  }
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    cout << dp[n][k] * f[k] % mod << '\n';
  }
  return 0;
}
