#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 100;
const int maxk = 45;
const int mod = 1000000007;
int dp[maxk][maxn];
int cnt[maxk][maxn];
void input_output() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    int n, k;
    cin >> n >> k;
    if (k < maxk)
      cout << dp[k][n] << endl;
    else
      cout << 0 << endl;
  }
}
void dpp() {
  for (int i = 0; i < maxn; i++) dp[0][i] = 1, cnt[0][i] = i + 1;
  for (int i = 1; i < 45; i++) {
    for (int j = i; j < maxn; j++) {
      dp[i][j] = (dp[i][j - i] + (long long)i * cnt[i - 1][j - i]) % mod;
      cnt[i][j] = (cnt[i][j - 1] + dp[i][j]) % mod;
    }
  }
}
int main() {
  dpp();
  input_output();
}
