#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > bruv(1020, vector<int>(50, 0));
const long long mod = 1e9 + 7;
long long power(long long base, long long exponent, long long modx = mod) {
  long long ret = 1 % modx;
  base %= modx;
  while (exponent) {
    if (exponent & 1) {
      ret = (ret * base) % modx;
    }
    base = (base * base) % modx;
    exponent >>= 1;
  }
  return ret;
}
long long inv(long long val, long long modx = mod) {
  return power(val, modx - 2, modx);
}
vector<long long> fac, ifac;
void preFac(long long sz) {
  fac.resize(sz + 1), ifac.resize(sz + 1);
  fac[0] = 1;
  for (int i = 1; i <= sz; i++) {
    fac[i] = (i * fac[i - 1]) % mod;
  }
  ifac[sz] = inv(fac[sz]);
  for (int i = sz - 1; i >= 0; i--) {
    ifac[i] = ((i + 1) * ifac[i + 1]) % mod;
  }
}
long long nCr(long long N, long long R) {
  if (R <= N && R >= 0) {
    return ((fac[N] * ifac[R]) % mod * ifac[N - R]) % mod;
  }
  return 0;
}
long long get_cnt(long long sm, long long var) {
  return nCr(sm + var - 1, var - 1);
}
long long ans[1003][1002];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  preFac(2020);
  bruv[0][0] = 1;
  for (int xi = 0; xi <= 1000; xi++) {
    auto cur = bruv;
    for (int yp = 0; yp < 49; yp++) {
      for (int xp = 0; xp <= 1000; xp++) {
        if (xi + xp <= 1000) {
          cur[xi + xp][yp + 1] += bruv[xp][yp];
          if (cur[xi + xp][yp + 1] >= mod) {
            cur[xi + xp][yp + 1] -= mod;
          }
        }
      }
    }
    bruv = cur;
  }
  for (int n = 0; n <= 1000; n++) {
    for (int k = 1; k < 50; k++) {
      if (bruv[n][k] == 0) {
        continue;
      }
      long long tem = 0;
      for (int ksm = 0; ksm <= n; ksm++) {
        tem += (long long)bruv[ksm][k] * get_cnt(n - ksm, k + 1);
        tem %= mod;
      }
      ans[n][k] = (tem * fac[k]) % mod;
    }
  }
  int T;
  cin >> T;
  while (T--) {
    int n, k;
    cin >> n >> k;
    n -= k;
    cout << ans[n][k] << '\n';
  }
  return 0;
}

### Prompt

Develop a solution in Cpp to the problem described below:

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;
vector<vector<int> > bruv(1020, vector<int>(50, 0));
const long long mod = 1e9 + 7;
long long power(long long base, long long exponent, long long modx = mod) {
  long long ret = 1 % modx;
  base %= modx;
  while (exponent) {
    if (exponent & 1) {
      ret = (ret * base) % modx;
    }
    base = (base * base) % modx;
    exponent >>= 1;
  }
  return ret;
}
long long inv(long long val, long long modx = mod) {
  return power(val, modx - 2, modx);
}
vector<long long> fac, ifac;
void preFac(long long sz) {
  fac.resize(sz + 1), ifac.resize(sz + 1);
  fac[0] = 1;
  for (int i = 1; i <= sz; i++) {
    fac[i] = (i * fac[i - 1]) % mod;
  }
  ifac[sz] = inv(fac[sz]);
  for (int i = sz - 1; i >= 0; i--) {
    ifac[i] = ((i + 1) * ifac[i + 1]) % mod;
  }
}
long long nCr(long long N, long long R) {
  if (R <= N && R >= 0) {
    return ((fac[N] * ifac[R]) % mod * ifac[N - R]) % mod;
  }
  return 0;
}
long long get_cnt(long long sm, long long var) {
  return nCr(sm + var - 1, var - 1);
}
long long ans[1003][1002];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  preFac(2020);
  bruv[0][0] = 1;
  for (int xi = 0; xi <= 1000; xi++) {
    auto cur = bruv;
    for (int yp = 0; yp < 49; yp++) {
      for (int xp = 0; xp <= 1000; xp++) {
        if (xi + xp <= 1000) {
          cur[xi + xp][yp + 1] += bruv[xp][yp];
          if (cur[xi + xp][yp + 1] >= mod) {
            cur[xi + xp][yp + 1] -= mod;
          }
        }
      }
    }
    bruv = cur;
  }
  for (int n = 0; n <= 1000; n++) {
    for (int k = 1; k < 50; k++) {
      if (bruv[n][k] == 0) {
        continue;
      }
      long long tem = 0;
      for (int ksm = 0; ksm <= n; ksm++) {
        tem += (long long)bruv[ksm][k] * get_cnt(n - ksm, k + 1);
        tem %= mod;
      }
      ans[n][k] = (tem * fac[k]) % mod;
    }
  }
  int T;
  cin >> T;
  while (T--) {
    int n, k;
    cin >> n >> k;
    n -= k;
    cout << ans[n][k] << '\n';
  }
  return 0;
}

```