![排列计数.png](https://i.loli.net/2019/10/10/pCmD3FYjIM4A6qR.png)
#define int long long
int n,m;
const int N=1e6+10,mod=1e9+7;
int D[N],fac[N];
inline int ksm(int a,int k,int mod){
int res=1;
for(;k;k>>=1){
if(k&1)
res=res*a%mod;
a=a*a%mod;
}
return res;
}
#undef int
int main(){
#define int long long
freopen("test.txt","r",stdin);
int T;rd(T);
D[0]=1,D[1]=0;
rep(i,2,N-10)
D[i]=(D[i-1]+D[i-2])*(i-1)%mod;
fac[0]=1;
rep(i,1,N-10)
fac[i]=fac[i-1]*i%mod;
while(T--){
rd(n),rd(m);
printf("%lld\n",fac[n]*ksm(fac[m],mod-2,mod)%mod*ksm(fac[n-m],mod-2,mod)%mod*D[n-m]%mod);
}
return 0;
}