#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 + 5, MOD = 1e9 + 7, K = 49, N = 2e4 + 1;
int dp[MAXN][K], ans[MAXN][K];
long long fac[N], inv[N];
int t;
long long pw(long long a, long long b) {
  if (b == 0) return 1LL;
  if (b % 2)
    return (pw(a * a % MOD, b / 2LL) * a) % MOD;
  else
    return pw(a * a % MOD, b / 2LL) % MOD;
}
int c(int k, int n) {
  if (k < 0 || k > n) return 0;
  int ans = (fac[n] * inv[k]) % MOD;
  ans = (ans * inv[n - k]) % MOD;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  fac[0] = 1, inv[0] = 1;
  for (int i = 1; i < N; i++)
    fac[i] = (1LL * fac[i - 1] * i) % MOD, inv[i] = pw(fac[i], MOD - 2LL) % MOD;
  dp[0][0] = 1;
  for (int x = 0; x < MAXN; x++)
    for (int kp = K - 2; kp >= 0; kp--)
      for (int i = 0; i < MAXN - x; i++)
        dp[i + x][kp + 1] = (dp[i + x][kp + 1] % MOD +
                             (((long long)(kp + 1) * dp[i][kp]) % MOD)) %
                            MOD;
  for (int i = 0; i < MAXN; i++)
    for (int kp = 0; kp < K; kp++)
      for (int j = 0; j <= i; j++)
        ans[i][kp] =
            (ans[i][kp] + ((1LL * dp[j][kp] * c(kp, i - j)) % MOD)) % MOD;
  cin >> t;
  while (t) {
    t--;
    int n, k;
    cin >> n >> k;
    if (k < K)
      cout << ans[n][k] % MOD << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}

### Prompt

Create a solution in Cpp for 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;
const int MAXN = 1000 + 5, MOD = 1e9 + 7, K = 49, N = 2e4 + 1;
int dp[MAXN][K], ans[MAXN][K];
long long fac[N], inv[N];
int t;
long long pw(long long a, long long b) {
  if (b == 0) return 1LL;
  if (b % 2)
    return (pw(a * a % MOD, b / 2LL) * a) % MOD;
  else
    return pw(a * a % MOD, b / 2LL) % MOD;
}
int c(int k, int n) {
  if (k < 0 || k > n) return 0;
  int ans = (fac[n] * inv[k]) % MOD;
  ans = (ans * inv[n - k]) % MOD;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  fac[0] = 1, inv[0] = 1;
  for (int i = 1; i < N; i++)
    fac[i] = (1LL * fac[i - 1] * i) % MOD, inv[i] = pw(fac[i], MOD - 2LL) % MOD;
  dp[0][0] = 1;
  for (int x = 0; x < MAXN; x++)
    for (int kp = K - 2; kp >= 0; kp--)
      for (int i = 0; i < MAXN - x; i++)
        dp[i + x][kp + 1] = (dp[i + x][kp + 1] % MOD +
                             (((long long)(kp + 1) * dp[i][kp]) % MOD)) %
                            MOD;
  for (int i = 0; i < MAXN; i++)
    for (int kp = 0; kp < K; kp++)
      for (int j = 0; j <= i; j++)
        ans[i][kp] =
            (ans[i][kp] + ((1LL * dp[j][kp] * c(kp, i - j)) % MOD)) % MOD;
  cin >> t;
  while (t) {
    t--;
    int n, k;
    cin >> n >> k;
    if (k < K)
      cout << ans[n][k] % MOD << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}

```