#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long int ll;

const ll N = 1001;
const ll K = 1001;
ll n,k;
ll dp[N+1][K+1][2];
//memoization
ll dpHelper(ll k,ll curr,ll dir){
    if(k==1)return dp[curr][k][dir]=1;
    if(dp[curr][k][dir]!=-1)return dp[curr][k][dir];
    ll ans=2;
    if(dir==1){ //right
        if(curr<n){
            ans+=dpHelper(k,curr+1,dir)-1;
        }
        ans%=MOD;
        if(curr>1){
            ans+=dpHelper(k-1,curr-1,!dir)-1;
        }
        ans%=MOD;
        dp[curr][k][dir]=ans;
    }
    else{ //left (dir=0)
        if(curr>1){
            ans+=dpHelper(k,curr-1,dir)-1;
        }
        ans%=MOD;
        if(curr<n){
            ans+=dpHelper(k-1,curr+1,!dir)-1;
        }
        ans%=MOD;
        dp[curr][k][dir]=ans;
    }
    return dp[curr][k][dir]=ans;
}
void solve(){
    cin>>n>>k;
    memset(dp,-1,sizeof(dp));
    // directions : right=1 left=0
    cout<<dpHelper(k,1,1)<<"\n";
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll tc;
    tc = 1;
    cin >> tc;
    while (tc--){
        solve();
    }
    return 0;
}
