#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; typedef long double LB; #define N 101 #define mod 1000000007 #define PI acos(-1) const int INF=INT_MAX; int main() { int t; LL n,k,d,sum,a,b,x; scanf("%d",&t); while(t--) { scanf("%I64d%I64d",&n,&k); if((1+k)*k/2>n) {printf("-1\n");continue;} sum=(1+k)*k/2; d=n-sum; a=d/k; b=d%k; LL ans=1; for(int i=1;i<=k;i++) { if(i<=k-b) ans=(ans*(i+a))%mod; else ans=(ans*(i+a+1))%mod; } printf("%I64d\n",ans); } return 0; }