#include #include #include #include #include #define inf 1000000000 #define mod 1000000007 using namespace std; long long cas,x,k,num1,num2,s2,ans,j,i; long long sqr(long long x) {return x*x%mod;} long long ksm(long long x,long long y) { if (!y)return 1; if (y==1)return x; if (y%2)return sqr(ksm(x,y/2))%mod*x%mod; else return sqr(ksm(x,y/2))%mod; } int main() { scanf("%I64d",&cas); while (cas--) { scanf("%I64d%I64d",&x,&k); if ((1+k)*k/2>x){puts("-1");continue;} i=(2*x-k*k+k)/(2*k); ans=1; s2=x-(i+i+k-1)*k/2; for (j=i;j<=i+k-1;j++) if (i+k-j<=s2)ans=ans*(j+1)%mod;else ans=ans*j%mod; printf("%I64d\n",ans); } }