#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

#define ll long long int
#define lld long double
#define debug(x) cerr << "[" <<#x << " = " << x << "]" << endl
#define debug2(x, y) cerr << "[" <<#x << " = " << x << "]" << ", [" <<#y << " = " << y << "]" << endl

void DBG() {
	cerr << "]" << endl;
}
template<class H, class... T> void DBG(H h, T... t) {
	cerr << h;
	if(sizeof...(t))
		cerr << ", ";
	DBG(t...);
}

template<class H> void DBG(vector<H> v){
	for(int i=0 ; i<(int)v.size() ; i++){
		cerr << v[i];
		if(i != (int)v.size()-1) cerr << ", ";
	}
	cerr << ']' << endl;
}
#ifdef _DEBUG
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

const lld pi = 3.14159265358979323846;
const ll mod = 1000000007;
mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 rng(61378913);
/* usage - just do rng() - from colin */

ll randNum(ll a , ll b){
	return a + rand() % (b-a+1);
}


ll gcd(ll a, ll b)
{
  if (b == 0)
    return a;
  return gcd(b, a % b);
}


ll lcm(ll a, ll b)
{
    return (a / gcd(a, b)) * b;
}

ll mPow(ll b, ll p , ll m) {
	b %= m;
	ll result = 1;
	while(p > 0) {
		if(p & 1) result = (result * b) % m;
		b = ((ll)b * b) % m;
		p >>= 1;
	}
	return result;
}



ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
   
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
  
    ll x1, y1;
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
  
    *x = y1 - (b/a) * x1; 
    *y = x1; 
  
    return gcd; 
} 

ll modInverse(ll b, ll m) 
{ 
    ll x, y;
    ll g = gcdExtended(b, m, &x, &y); 
  
    if (g != 1) 
        return -1; 
  
    return (x%m + m) % m; 
} 
  
ll modDivide(ll a, ll b, ll m) 
{ 
    a = a % m; 
    ll inv = modInverse(b, m); 
    if (inv == -1) 
       return -1; 
    else
       return (inv * a) % m; 
} 

//precompute factorial array if multiple queries are present
unsigned long long nCrModPFermat(unsigned long long n, int r, int p){
	
    if (n < (unsigned long long)r)
        return 0;
    if (r == 0)
        return 1;
 
    unsigned long long fac[n + 1];
    fac[0] = 1;
    for (unsigned long long i = 1; i <= n; i++)
        fac[i] = (fac[i - 1] * i) % p;
 
    return (fac[n] * modInverse(fac[r], p) % p
            * modInverse(fac[n - r], p) % p)
           % p;
}

const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};

//----------------------------

void testcase(){
	int n , k;
	cin >> n >> k;
	vector<int> rays(n-1 , 0);
	ll total = 1;
	ll singlesum = 1;
	k--;
	while(k > 0){
		//dbg(k);
		if(k == 1) total++;
		vector<int> temp(n-1 , 0);
		if(n != 1) temp[0] = singlesum;
		for(int i=0 ; i<n-2 ; i++){
			temp[i+1] = (temp[i]+mod - rays[i])%mod;
		}
		
		reverse(temp.begin() , temp.end());
		rays = temp;
		singlesum = 0;
		for(auto i : rays) singlesum = (singlesum + i)%mod;
		total = (total + singlesum)%mod;
		//dbg(rays);
		//dbg(singlesum);
		//dbg(total);
		k--;
	}
	cout << total << "\n";
}

int main(){
	cin.sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    int tt = 1;
    cin>>tt;
    tt++;
    while(--tt){
        testcase();
    }
    return 0;
    
}
