#include <bits/stdc++.h>
using namespace std;
long long int pw(long long int a, long long int b, long long int mod) {
  if (!b) return 1;
  if (b & 1) return a * pw(a * a % mod, b / 2, mod) % mod;
  return pw(a * a % mod, b / 2, mod) % mod;
}
const long long int MAXN = 1e3 + 10;
const long long int INF = 8e18;
const long long int MOD = 1e9 + 7;
long long int t, fact[MAXN], inv[MAXN], dp[MAXN][MAXN], n, k, ans;
map<pair<long long int, long long int>, long long int> mp;
inline long long int C(long long int n, long long int r) {
  if (r > n) return 0;
  return fact[n] * inv[r] % MOD * inv[n - r] % MOD;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  fact[0] = inv[0] = 1;
  for (long long int i = 1; i < MAXN; i++) {
    fact[i] = i * fact[i - 1] % MOD;
    inv[i] = pw(fact[i], MOD - 2, MOD);
  }
  dp[0][0] = 1;
  for (long long int i = 1; i < MAXN; i++) {
    dp[i][1] = 1;
    for (long long int j = 2; j < MAXN; j++) {
      for (long long int k = 1; k * j <= i; k++) {
        dp[i][j] = (dp[i][j] + dp[i - j * k][j - 1]) % MOD;
      }
    }
  }
  cin >> t;
  while (t--) {
    cin >> n >> k;
    if (mp.find({n, k}) != mp.end()) {
      cout << mp[{n, k}] << '\n';
      continue;
    }
    ans = 0;
    for (long long int i = k * (k - 1) / 2; i < n; i++) {
      ans += dp[i + k][k] * fact[k] % MOD * C(n - i, k) % MOD;
      ans %= MOD;
    }
    cout << ans << '\n';
    mp[{n, k}] = ans;
  }
  return 0;
}

### Prompt

Your challenge is to write a cpp solution to the following problem:

The sequence of integer pairs (a1, b1), (a2, b2), ..., (ak, bk) is beautiful, if the following statements are fulfilled: 

  * 1 ≤ a1 ≤ b1 < a2 ≤ b2 < ... < ak ≤ bk ≤ n, where n is a given positive integer; 
  * all numbers b1 - a1, b2 - a2, ..., bk - ak are distinct. 



For the given number n find the number of beautiful sequences of length k. As the answer can be rather large, print the remainder after dividing it by 1000000007 (109 + 7).

Input

The first line contains integer t (1 ≤ t ≤ 2·105) — the number of the test data.

Each of the next t lines contains two integers n and k (1 ≤ k ≤ n ≤ 1000).

Output

For each test from the input print the answer to the problem modulo 1000000007 (109 + 7). Print the answers to the tests in the order in which the tests are given in the input.

Examples

Input

6
1 1
2 1
2 2
3 1
3 2
3 3


Output

1
3
0
6
2
0

Note

In the first test sample there is exactly one beautiful sequence: (1, 1).

In the second test sample, the following sequences are beautiful: 

  * (1, 1); 
  * (1, 2); 
  * (2, 2). 



In the fourth test sample, the following sequences are beautiful: 

  * (1, 1); 
  * (1, 2); 
  * (1, 3); 
  * (2, 2); 
  * (2, 3); 
  * (3, 3). 



In the fifth test sample, the following sequences are beautiful: 

  * (1, 1), (2, 3); 
  * (1, 2), (3, 3). 



In the third and sixth samples, there are no beautiful sequences.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int pw(long long int a, long long int b, long long int mod) {
  if (!b) return 1;
  if (b & 1) return a * pw(a * a % mod, b / 2, mod) % mod;
  return pw(a * a % mod, b / 2, mod) % mod;
}
const long long int MAXN = 1e3 + 10;
const long long int INF = 8e18;
const long long int MOD = 1e9 + 7;
long long int t, fact[MAXN], inv[MAXN], dp[MAXN][MAXN], n, k, ans;
map<pair<long long int, long long int>, long long int> mp;
inline long long int C(long long int n, long long int r) {
  if (r > n) return 0;
  return fact[n] * inv[r] % MOD * inv[n - r] % MOD;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  fact[0] = inv[0] = 1;
  for (long long int i = 1; i < MAXN; i++) {
    fact[i] = i * fact[i - 1] % MOD;
    inv[i] = pw(fact[i], MOD - 2, MOD);
  }
  dp[0][0] = 1;
  for (long long int i = 1; i < MAXN; i++) {
    dp[i][1] = 1;
    for (long long int j = 2; j < MAXN; j++) {
      for (long long int k = 1; k * j <= i; k++) {
        dp[i][j] = (dp[i][j] + dp[i - j * k][j - 1]) % MOD;
      }
    }
  }
  cin >> t;
  while (t--) {
    cin >> n >> k;
    if (mp.find({n, k}) != mp.end()) {
      cout << mp[{n, k}] << '\n';
      continue;
    }
    ans = 0;
    for (long long int i = k * (k - 1) / 2; i < n; i++) {
      ans += dp[i + k][k] * fact[k] % MOD * C(n - i, k) % MOD;
      ans %= MOD;
    }
    cout << ans << '\n';
    mp[{n, k}] = ans;
  }
  return 0;
}

```