#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F(i, a, b) for (int i = a; i <= b; i++)
int M = 1000000007;
int val[1001][1001];
int n,k;
int dp(int cur,int rem)
{
if(cur<1 || cur>k || rem<0 || rem>n)return 0;
if(cur==1 || rem==0)return 1;
if(val[cur][rem]==-1)
{
int ans=0;
ans+=dp(cur,rem-1);
ans%=M;
ans+=dp(cur-1,n-rem);
ans%=M;
val[cur][rem]=ans;
}
return val[cur][rem];
}
void solve()
{
cin>>n>>k;
F(i,0,k)F(j,0,n)val[i][j]=-1;
cout<<dp(k,n);
cout<<"\n";
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int _t=1;
cin>>_t;
for (int i=1;i<=_t;i++)
{
solve();
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojZGVmaW5lIGludCBsb25nIGxvbmcKI2RlZmluZSBGKGksIGEsIGIpIGZvciAoaW50IGkgPSBhOyBpIDw9IGI7IGkrKykKaW50IE0gPSAxMDAwMDAwMDA3OwoKaW50IHZhbFsxMDAxXVsxMDAxXTsKaW50IG4sazsKaW50IGRwKGludCBjdXIsaW50IHJlbSkKewogICAgaWYoY3VyPDEgfHwgY3VyPmsgfHwgcmVtPDAgfHwgcmVtPm4pcmV0dXJuIDA7CiAgICBpZihjdXI9PTEgfHwgcmVtPT0wKXJldHVybiAxOwoKICAgIGlmKHZhbFtjdXJdW3JlbV09PS0xKQogICAgewogICAgICAgIGludCBhbnM9MDsKICAgICAgICBhbnMrPWRwKGN1cixyZW0tMSk7CiAgICAgICAgYW5zJT1NOwogICAgICAgIGFucys9ZHAoY3VyLTEsbi1yZW0pOwogICAgICAgIGFucyU9TTsKICAgICAgICB2YWxbY3VyXVtyZW1dPWFuczsKICAgIH0KCiAgICByZXR1cm4gdmFsW2N1cl1bcmVtXTsKICAgIAp9Cgp2b2lkIHNvbHZlKCkKewogICAgY2luPj5uPj5rOwoKICAgIEYoaSwwLGspRihqLDAsbil2YWxbaV1bal09LTE7CgogICAgY291dDw8ZHAoayxuKTsKICAgIGNvdXQ8PCJcbiI7Cn0KCnNpZ25lZCBtYWluKCkKewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CiAgICBjaW4udGllKG51bGxwdHIpOwogICAgY291dC50aWUobnVsbHB0cik7CgogICAgaW50IF90PTE7CiAgICBjaW4+Pl90OwogICAgZm9yIChpbnQgaT0xO2k8PV90O2krKykKICAgIHsKICAgICAgICBzb2x2ZSgpOwogICAgfQogICAgcmV0dXJuIDA7Cn0=