#include <bits/stdc++.h>
namespace TNT {
const int MAXN = 1e3;
const int mod = 1e9 + 7;
inline int read() {
  int x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x;
}
void write(int x) {
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
int fac[MAXN + 10], inv[MAXN + 10];
inline int qpow(int x, int y) {
  int ans = 1;
  while (y) {
    if (y & 1) ans = 1ll * x * ans % mod;
    x = 1ll * x * x % mod;
    y >>= 1;
  }
  return ans;
}
inline int C(int n, int m) {
  if (n < m) return 0;
  return 1ll * (1ll * fac[n] * inv[n - m] % mod) * inv[m] % mod;
}
int f[51][MAXN + 10], ans[MAXN + 10][51];
inline void init() {
  inv[0] = inv[1] = fac[0] = fac[1] = 1;
  for (register int i = 2; i <= MAXN; i++) fac[i] = 1ll * fac[i - 1] * i % mod;
  inv[MAXN] = qpow(fac[MAXN], mod - 2);
  for (register int i = 999; i >= 2; i--)
    inv[i] = 1ll * inv[i + 1] * (i + 1) % mod;
  f[0][0] = 1;
  for (register int i = 1; i <= 50; i++)
    for (register int j = i * (i + 1) / 2; j <= MAXN; j++)
      f[i][j] = 1ll * (1ll * f[i - 1][j - i] + 1ll * f[i][j - i]) % mod;
  for (register int i = 1; i <= MAXN; i++)
    for (register int j = 1; j <= 50; j++) {
      for (int k = j * (j + 1) / 2; k <= i; k++)
        ans[i][j] =
            1ll * (ans[i][j] + 1ll * C(i - k + j, j) * f[j][k] % mod) % mod;
      ans[i][j] = 1ll * ans[i][j] * fac[j] % mod;
    }
}
inline void main() {
  int t = read();
  init();
  while (t--) {
    int n = read(), k = read();
    if (k > 50)
      puts("0");
    else
      write(ans[n][k]), putchar('\n');
  }
  return;
}
}  // namespace TNT
int main() {
  TNT::main();
  return 0;
}

### Prompt

Construct a Cpp code solution to the problem outlined:

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>
namespace TNT {
const int MAXN = 1e3;
const int mod = 1e9 + 7;
inline int read() {
  int x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x;
}
void write(int x) {
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
int fac[MAXN + 10], inv[MAXN + 10];
inline int qpow(int x, int y) {
  int ans = 1;
  while (y) {
    if (y & 1) ans = 1ll * x * ans % mod;
    x = 1ll * x * x % mod;
    y >>= 1;
  }
  return ans;
}
inline int C(int n, int m) {
  if (n < m) return 0;
  return 1ll * (1ll * fac[n] * inv[n - m] % mod) * inv[m] % mod;
}
int f[51][MAXN + 10], ans[MAXN + 10][51];
inline void init() {
  inv[0] = inv[1] = fac[0] = fac[1] = 1;
  for (register int i = 2; i <= MAXN; i++) fac[i] = 1ll * fac[i - 1] * i % mod;
  inv[MAXN] = qpow(fac[MAXN], mod - 2);
  for (register int i = 999; i >= 2; i--)
    inv[i] = 1ll * inv[i + 1] * (i + 1) % mod;
  f[0][0] = 1;
  for (register int i = 1; i <= 50; i++)
    for (register int j = i * (i + 1) / 2; j <= MAXN; j++)
      f[i][j] = 1ll * (1ll * f[i - 1][j - i] + 1ll * f[i][j - i]) % mod;
  for (register int i = 1; i <= MAXN; i++)
    for (register int j = 1; j <= 50; j++) {
      for (int k = j * (j + 1) / 2; k <= i; k++)
        ans[i][j] =
            1ll * (ans[i][j] + 1ll * C(i - k + j, j) * f[j][k] % mod) % mod;
      ans[i][j] = 1ll * ans[i][j] * fac[j] % mod;
    }
}
inline void main() {
  int t = read();
  init();
  while (t--) {
    int n = read(), k = read();
    if (k > 50)
      puts("0");
    else
      write(ans[n][k]), putchar('\n');
  }
  return;
}
}  // namespace TNT
int main() {
  TNT::main();
  return 0;
}

```