#include #include #include #define MN 1000 typedef long long LL; const int mod=1000000007; int n,m,f[MN][MN][11]; //f[长度][数量][连续数量] int calc(int n){ return std::max((n-2)-(n-2)/11,0); } void solve(){ scanf("%d%d",&n,&m); memset(f,0,sizeof(f)); if(m>calc(n)){ puts("-1"); return; } f[1][0][0] = 1; for(int i=2;i<=n-1;i++){ int lim=std::min(i,m); for(int j=0;j<=lim;j++){ int lim=std::min(j,10); for(int k=0;k<=lim;k++) f[i][j][0] = (f[i][j][0]+f[i-1][j][k])%mod; for(int k=1;k<=lim;k++) f[i][j][k] = (1ll*f[i-1][j-1][k-1]*(i-1))%mod; } } int ans = 0; for(int k=0;k<=10;k++) ans = (ans+f[std::max(n-1,1)][m][k])%mod; printf("%d\n",ans); } int main(){ int T; scanf("%d",&T); while(T--) solve(); }