#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ffor(i,n) for(auto i=(n)-(n);i<(n);i++)
#define printf(...) ({char _b[999]; sprintf(_b,__VA_ARGS__); cout<<string(_b); 0;})
#define printv(v) ({ffor(_o,v.size()) printf("%4lld ",1ll*v[_o]); printf("\n");})
#define opt(x,f,u) (x=f(x,u))
#define PRIME ((ll)1e9 + 7LL) // (ll 1e18+3LL)
#define padd(a,b) ((1LL*(a)+(b))%PRIME) 
#define psub(a,b) ((1LL*(a)+(PRIME - (b)))%PRIME) 
#define pmul(a,b) ((1LL*((a)%PRIME)*((b)%PRIME))%PRIME)
ll n;
int tc=-1; // -1: cin
int solve();
int main(){ios_base::sync_with_stdio(0); if(tc<0) cin>>tc; while(tc-->0) solve(); return 0;}

int solve(){
  ll k;
  cin >> n >> k;
  if(n==1){
    cout << 1+(k>1) << endl;
    return 0;
  }
  if(k==1){
    cout << 1 << endl;
    return 0;
  }
  vector<int> acc(n-1,1);
  ll s=n+1;
  while(--k){
    if(k%2){
      for(int j=1;j<n-1;j++)
        acc[j]=padd(acc[j],acc[j-1]);
    }else{
      for(int j=n-3;j>-1;j--)
        acc[j]=padd(acc[j],acc[j+1]);
    }
    if(k>1) 
      ffor(j,n-1)
        s = padd(s,acc[j]);
  }
  cout << s << endl;
  return 0;
}
