#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll t = 1,n,m,f[1009][1009],g[1009][1009],a,b,c,u,v,x,y,z,mod = 1e9 + 7;
string s;
ll qp(ll x,ll y){
	ll a = 1,b = x;
	while (y){
		if (y & 1) a = a * b % mod;
		b = b * b % mod,y >>= 1;
	}
	return a;
}
int main(){cin>>t;
while (t --){
	cin>>n>>m; ll ans = n + 1;
	if (m == 1){cout<<1<<endl; continue;}
	for (ll i = 1;i < n;i += 1) g[1][i] = 1;
	for (ll i = 2;i < m;i += 1) g[i][n] = 0;
	for (ll i = 2;i < m;i += 1){
		if (i & 1)
			for (ll j = 1;j < n;j += 1){
				g[i][j] = (g[i - 1][j] + g[i][j - 1]) % mod,ans = (ans + g[i][j]) % mod;
			}
		else
			for (ll j = n - 1;j >= 1;j -= 1){
				g[i][j] = (g[i - 1][j] + g[i][j + 1]) % mod,ans = (ans + g[i][j]) % mod;
			}
	}
	cout<<ans<<endl;
}
	return 0;
}