#include <bits/stdc++.h>
#define ll long long
#define ull long long int
#define pb push_back
#define vi vector<int>
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define MOD 1000000007
#define ff first
#define ss second
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
using namespace std;
#define pr(x) cout << #x << " = " << x << endl;

/*-------------------------------------------------------------------------------*/
ll expo(ll a, ll b, ll mod)
{
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = (res * a) % mod;
        a = (a * a) % mod;
        b = b >> 1;
    }
    return res;
}
void extendgcd(ll a, ll b, ll *v)
{
    if (b == 0)
    {
        v[0] = 1;
        v[1] = 0;
        v[2] = a;
        return;
    }
    extendgcd(b, a % b, v);
    ll x = v[1];
    v[1] = v[0] - v[1] * (a / b);
    v[0] = x;
    return;
} //pass an arry of size1 3
ll mminv(ll a, ll b)
{
    ll arr[3];
    extendgcd(a, b, arr);
    return arr[0];
} //for non prime b
ll mminvprime(ll a, ll b) { return expo(a, b - 2, b); }
ll mod_add(ll a, ll b, ll m)
{
    a = a % m;
    b = b % m;
    return (((a + b) % m) + m) % m;
}
ll mod_mul(ll a, ll b, ll m)
{
    a = a % m;
    b = b % m;
    return (((a * b) % m) + m) % m;
}
ll mod_sub(ll a, ll b, ll m)
{
    a = a % m;
    b = b % m;
    return (((a - b) % m) + m) % m;
}
ll mod_div(ll a, ll b, ll m)
{
    a = a % m;
    b = b % m;
    return (mod_mul(a, mminvprime(b, m), m) + m) % m;
}
const ll factN = 3e5 + 5;
ll fact[factN];
void factorial(int n, ll m)
{
    fact[0] = 1;
    for (int i = 1; i <= n; i++)
        fact[i] = mod_mul(fact[i - 1], i, m);
}
ll ncr(ll n, ll r, ll m)
{
    ll n1 = fact[n];
    ll n2 = mod_mul(fact[r], fact[n - r], m);
    n2 = expo(n2, m - 2, m);
    return mod_mul(n1, n2, m);
}
/*--------------------------------------------------------------------------------*/

void solve(int tc)
{
    int n, k;
    cin >> n >> k;
    ll ans = 1;
    if(k==1)
    {
        cout << 1 << endl;
        return;
    }
    ll pre[k-1][n];
    memset(pre,0,sizeof(pre));
    
    for (int i = 0; i < n; i++)
    {
        pre[0][i] = 1; // left
    }
    ll f = 1;
    //1-> right, 0 > left
    for(int i =1; i < k-1; i++)
    {
        if(f==0)
        {
            f=1;
            pre[i][0] =0;
            for(int j =1; j < n; j++)
            {
                pre[i][j] = mod_add(pre[i-1][j-1],pre[i][j-1], MOD);
            }
        }
        else
        {
            f=0;
            pre[i][n-1] =0;
            for(int j =n-2; j >=0; j--)
            {
                pre[i][j] = mod_add(pre[i-1][j+1], pre[i][j+1], MOD);
            }
        }
    }
 
    for(int i =0; i < k-1; i++)
    {
        for(int j =0; j < n; j++)
        {
            ans = mod_add(pre[i][j], ans,MOD);
        }
    }
    cout << ans << endl;
}
int main()
{
    fast
#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int tc = 1;
    cin >> tc;

    for (int i = 1; i <= tc; i++)
    {
        solve(i);
    }

    return 0;
}
