#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(i,s,t) for(register int i=s;i<=t;++i) #define _rep(i,s,t) for(register int i=s;i>=t;--i) #define Rep(i,s,t) for(register int i=s;i #define ms(f,x) memset(f,x,sizeof f) #define mc(f,x) memcpy(f,x,sizeof f) #define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout) #define gi(x) read(x) #define gii(x,y) read(x),read(y) #define giii(x,y,z) read(x),read(y),read(z) namespace IO { #define gc getchar() #define pc(x) putchar(x) templateinline void read(T &x) { x=0; int f=1; char ch=gc; while(ch>'9'||ch<'0') { if(ch=='-')f=-1; ch=gc; } while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=gc; x*=f; return; } templateinline void write(T x=0) { T wr[51]; wr[0]=0; if(x<0)pc('-'),x=-x; if(!x)pc(48); while(x)wr[++wr[0]]=x%10,x/=10; while(wr[0])pc(48+wr[wr[0]--]); return; } } using IO::read; using IO::write; typedef long long ll; typedef double db; typedef long double ld; typedef unsigned long long ull; using namespace std; const int N=1e6+11; int T; int n,m,mx1,mx2,op,x,nw,p; int f[2011][2011],b[2011][2011]; const int mod=1e9+7; int main(){ f[1][0]=1,b[1][0]=1; rep(i,1,1000){ nw=1,p=min(i+11,1000); rep(j,i+1,p){ if(j!=i+1)nw=1ll*nw*(j-2)%mod; rep(k,0,j) b[j][k+j-i-1]|=b[i][k], f[j][k+j-i-1]=(f[j][k+j-i-1]+1ll*nw*f[i][k]%mod)%mod; } } scanf("%d",&T); while(T--){ scanf("%d%d",&n,&m); if(b[n][m]==0)puts("-1"); else printf("%d\n",f[n][m]); } return 0; } /* 2 2 1 1 2 1 2 1 2 2 1 */