#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 7;
const int P = 1e9 + 7;
int f[N << 1], rf[N << 1], dp[N][N], pd[N][N], ans[N][N];
inline void inc(int &x, int y) {
  x += y;
  if (x >= P) x -= P;
}
long long kpow(long long a, long long b) {
  long long r = 1;
  while (b > 0) {
    if (b & 1) r = r * a % P;
    a = a * a % P, b >>= 1;
  }
  return r;
}
inline int C(int n, int m) {
  if (n < m) return 0;
  return 1ll * f[n] * rf[m] % P * rf[n - m] % P;
}
void gao() {
  f[0] = 1;
  for (int i = (1); i < (N << 1); ++i) f[i] = 1ll * f[i - 1] * i % P;
  rf[2 * N - 1] = kpow(f[2 * N - 1], P - 2);
  for (int i = 2 * N - 2; i >= 0; --i) rf[i] = 1ll * rf[i + 1] * (i + 1) % P;
  dp[0][0] = 1;
  for (int k = 1; k * (k + 1) <= 2 * N; ++k) {
    for (int s = (0); s < (N); ++s)
      for (int v = (0); v < (N); ++v) {
        pd[s][v] = dp[s][v], dp[s][v] = 0;
        inc(pd[s][v], !v ? 0 : pd[s][v - 1]);
      }
    for (int v = (1); v < (N); ++v)
      for (int s = (v); s < (N); ++s) dp[s][v] = pd[s - v][v - 1];
    for (int n = (1); n < (N); ++n)
      for (int v = (0); v < (N); ++v) inc(ans[n][k], dp[n][v]);
    for (int n = N - 1; n > 0; --n) {
      int sum = 1;
      for (int s = n - 1; s > 0; --s) {
        inc(sum, C(n - s + k - 1, k - 1));
        inc(ans[n][k], 1ll * sum * ans[s][k] % P);
      }
      ans[n][k] = 1ll * ans[n][k] * f[k] % P;
    }
  }
}
int main() {
  gao();
  int T;
  scanf("%d", &T);
  for (int cas = (0); cas < (T); ++cas) {
    int n, k;
    scanf("%d%d", &n, &k);
    printf("%d\n", ans[n][k]);
  }
  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;
const int N = 1e3 + 7;
const int P = 1e9 + 7;
int f[N << 1], rf[N << 1], dp[N][N], pd[N][N], ans[N][N];
inline void inc(int &x, int y) {
  x += y;
  if (x >= P) x -= P;
}
long long kpow(long long a, long long b) {
  long long r = 1;
  while (b > 0) {
    if (b & 1) r = r * a % P;
    a = a * a % P, b >>= 1;
  }
  return r;
}
inline int C(int n, int m) {
  if (n < m) return 0;
  return 1ll * f[n] * rf[m] % P * rf[n - m] % P;
}
void gao() {
  f[0] = 1;
  for (int i = (1); i < (N << 1); ++i) f[i] = 1ll * f[i - 1] * i % P;
  rf[2 * N - 1] = kpow(f[2 * N - 1], P - 2);
  for (int i = 2 * N - 2; i >= 0; --i) rf[i] = 1ll * rf[i + 1] * (i + 1) % P;
  dp[0][0] = 1;
  for (int k = 1; k * (k + 1) <= 2 * N; ++k) {
    for (int s = (0); s < (N); ++s)
      for (int v = (0); v < (N); ++v) {
        pd[s][v] = dp[s][v], dp[s][v] = 0;
        inc(pd[s][v], !v ? 0 : pd[s][v - 1]);
      }
    for (int v = (1); v < (N); ++v)
      for (int s = (v); s < (N); ++s) dp[s][v] = pd[s - v][v - 1];
    for (int n = (1); n < (N); ++n)
      for (int v = (0); v < (N); ++v) inc(ans[n][k], dp[n][v]);
    for (int n = N - 1; n > 0; --n) {
      int sum = 1;
      for (int s = n - 1; s > 0; --s) {
        inc(sum, C(n - s + k - 1, k - 1));
        inc(ans[n][k], 1ll * sum * ans[s][k] % P);
      }
      ans[n][k] = 1ll * ans[n][k] * f[k] % P;
    }
  }
}
int main() {
  gao();
  int T;
  scanf("%d", &T);
  for (int cas = (0); cas < (T); ++cas) {
    int n, k;
    scanf("%d%d", &n, &k);
    printf("%d\n", ans[n][k]);
  }
  return 0;
}

```