#include<bits/stdc++.h>
using namespace std;
long long p=1000000007;
long long fmod(long long x){
if(x==1)return 1;
return ((x%p)*fmod(x-1))%p;
}
///using fermats little theorem
long long mmi(long long x){
long long y = p-2;
long long result = 1;
while(y){
if(y&1)result = (result*x)%p;
x = (x*x)%p;
y>>=1;
}
return result;
}
int main(){
int t;
cin>>t;
while(t--){
long long n,m;
cin>>n>>m;
printf("%lld\n", ((fmod(m+n-2)*mmi(((fmod(m-1)%p)*(fmod(n-1)%p))%p))%p));
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKbG9uZyBsb25nIHA9MTAwMDAwMDAwNzsKbG9uZyBsb25nIGZtb2QobG9uZyBsb25nIHgpewogICAKICAgIGlmKHg9PTEpcmV0dXJuIDE7CiAgICByZXR1cm4gKCh4JXApKmZtb2QoeC0xKSklcDsKfQovLy91c2luZyBmZXJtYXRzIGxpdHRsZSB0aGVvcmVtCmxvbmcgbG9uZyBtbWkobG9uZyBsb25nIHgpewogICAgbG9uZyBsb25nIHkgPSBwLTI7CiAgICBsb25nIGxvbmcgcmVzdWx0ID0gMTsKICAgIHdoaWxlKHkpewogICAgICAgIGlmKHkmMSlyZXN1bHQgPSAocmVzdWx0KngpJXA7CiAgICAgICAgeCA9ICh4KngpJXA7CiAgICAgICAgeT4+PTE7CiAgICB9CiAgICByZXR1cm4gcmVzdWx0Owp9CgppbnQgbWFpbigpewogICAgaW50IHQ7CiAgICBjaW4+PnQ7CiAgICB3aGlsZSh0LS0pewogICAgICAgIGxvbmcgbG9uZyBuLG07CiAgICAgICAgY2luPj5uPj5tOwogICAgICAgIHByaW50ZigiJWxsZFxuIiwgKChmbW9kKG0rbi0yKSptbWkoKChmbW9kKG0tMSklcCkqKGZtb2Qobi0xKSVwKSklcCkpJXApKTsKICAgIH0KCn0K
OQo1MjQ2NDUgMzc5MDE4CjkzNDEyNiA4ODg3NzEKODc3MjU1IDE4NzAwMgo3OTQzNzYgNzA0MzIwCjUxNTQyOSA5MjU3MDYKNzQ0NjQxIDU0NDcwMQo1MDA4MzEgMTQ3NDQzCjEzNDI0MSA1NDQxNjcKNDY2NzU1IDI2MzE4Ng==
9
524645 379018
934126 888771
877255 187002
794376 704320
515429 925706
744641 544701
500831 147443
134241 544167
466755 263186