#include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; const int mod=1e9+7; LL n,k; LL pd(LL pos){ return (pos+pos+k-1)*k/2; } void iwork() { if(pd(1)>n) { puts("-1"); return; } LL l=1; LL r=n; while(l<=r) { if(l+1==r || l==r) { if(pd(r)<=n) l=r; break; } LL Mid=(l+r)>>1; if(pd(Mid)<=n) l=Mid; else r=Mid-1; } LL delta=n-pd(l); LL x=(l+k-delta); LL ans=1; for(LL i=l;i<=l+k;i++) { if(i==x) continue; else ans=(ans*i)%mod; } printf("%I64d\n",ans); } int main() { int t; scanf("%d",&t); while(t--) { scanf("%lld%lld",&n,&k); iwork(); } return 0; }