#include <bits/stdc++.h>
using namespace std;
long long spf[2001];
long long fac[2001];
void sieve() {
  spf[1] = 1;
  for (long long i = 2; i < 2001; i++) spf[i] = i;
  for (long long i = 4; i < 2001; i += 2) spf[i] = 2;
  for (long long i = 3; i * i < 2001; i++) {
    if (spf[i] == i) {
      for (long long j = i * i; j < 2001; j += i)
        if (spf[j] == j) spf[j] = i;
    }
  }
}
map<long long, long long> getfactor(long long a) {
  map<long long, long long> m;
  while (a > 1) {
    m[spf[a]]++;
    a /= spf[a];
  }
  return m;
}
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  if (x == 0 || y < 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long inverse(long long a, long long p) { return power(a, p - 2, p); }
long long ncr(long long n, long long r, long long p) {
  if (r > n) return 0;
  if (r == 0 || r == n) return 1;
  return (fac[n] * inverse(fac[r], p) % p * inverse(fac[n - r], p) % p) % p;
}
long long dp[1001][51], dp2[1001][51];
long long nc[2001][2001];
void pre() {
  dp2[0][0] = 1;
  for (long long i = 1; i <= 1000; i++) {
    for (long long j = 1; j <= 1000; j++) {
      for (long long k = 1; k <= 50; k++) {
        dp[j][k] = dp2[j][k];
        if (j >= i) dp[j][k] += dp2[j - i][k - 1];
        dp[j][k] %= 1000000007;
      }
    }
    dp[0][0] = 1;
    for (long long j = 0; j <= 1000; j++)
      for (long long k = 0; k <= 50; k++) dp2[j][k] = dp[j][k];
  }
  for (long long i = 0; i <= 2000; i++)
    for (long long j = 0; j <= 2000; j++) nc[i][j] = ncr(i, j, 1000000007);
}
void solve() {
  long long n, k;
  cin >> n >> k;
  long long ans = 0;
  if (k > 50) {
    cout << 0 << '\n';
    return;
  }
  for (long long sum = 1; sum <= n; sum++) {
    ans += dp[sum][k] * nc[n - sum + k][k];
    ans %= 1000000007;
  }
  ans *= fac[k];
  ans %= 1000000007;
  cout << ans << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long test = 1;
  fac[0] = 1;
  for (long long i = 1; i <= 2000; i++) fac[i] = (fac[i - 1] * i) % 1000000007;
  pre();
  cin >> test;
  while (test--) {
    solve();
  }
}

### 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>
using namespace std;
long long spf[2001];
long long fac[2001];
void sieve() {
  spf[1] = 1;
  for (long long i = 2; i < 2001; i++) spf[i] = i;
  for (long long i = 4; i < 2001; i += 2) spf[i] = 2;
  for (long long i = 3; i * i < 2001; i++) {
    if (spf[i] == i) {
      for (long long j = i * i; j < 2001; j += i)
        if (spf[j] == j) spf[j] = i;
    }
  }
}
map<long long, long long> getfactor(long long a) {
  map<long long, long long> m;
  while (a > 1) {
    m[spf[a]]++;
    a /= spf[a];
  }
  return m;
}
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  if (x == 0 || y < 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long inverse(long long a, long long p) { return power(a, p - 2, p); }
long long ncr(long long n, long long r, long long p) {
  if (r > n) return 0;
  if (r == 0 || r == n) return 1;
  return (fac[n] * inverse(fac[r], p) % p * inverse(fac[n - r], p) % p) % p;
}
long long dp[1001][51], dp2[1001][51];
long long nc[2001][2001];
void pre() {
  dp2[0][0] = 1;
  for (long long i = 1; i <= 1000; i++) {
    for (long long j = 1; j <= 1000; j++) {
      for (long long k = 1; k <= 50; k++) {
        dp[j][k] = dp2[j][k];
        if (j >= i) dp[j][k] += dp2[j - i][k - 1];
        dp[j][k] %= 1000000007;
      }
    }
    dp[0][0] = 1;
    for (long long j = 0; j <= 1000; j++)
      for (long long k = 0; k <= 50; k++) dp2[j][k] = dp[j][k];
  }
  for (long long i = 0; i <= 2000; i++)
    for (long long j = 0; j <= 2000; j++) nc[i][j] = ncr(i, j, 1000000007);
}
void solve() {
  long long n, k;
  cin >> n >> k;
  long long ans = 0;
  if (k > 50) {
    cout << 0 << '\n';
    return;
  }
  for (long long sum = 1; sum <= n; sum++) {
    ans += dp[sum][k] * nc[n - sum + k][k];
    ans %= 1000000007;
  }
  ans *= fac[k];
  ans %= 1000000007;
  cout << ans << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long test = 1;
  fac[0] = 1;
  for (long long i = 1; i <= 2000; i++) fac[i] = (fac[i - 1] * i) % 1000000007;
  pre();
  cin >> test;
  while (test--) {
    solve();
  }
}

```