#include #include #include #include #include using namespace std; #define maxN 305 #define lson i<<1 #define rson (i<<1)+1 #define piii pair > #define pii pair #define F first #define S second #define mkp(a,b) make_pair(a,b) #define pb(x) push_back(x) typedef long long LL; LL m =1e9+7; int main() { LL n,k,T; scanf("%I64d",&T); while(T--) { scanf("%I64d %I64d",&n,&k); LL a = (2*n-k*(k-1))/(2*k); LL s = (a+a+k-1)*k/2; LL c = n - s; LL ans = 1; if(a<=0) { printf("-1\n"); continue; } for(LL i = a+k-1;i>=a;i--) { if(c) { ans = (ans*(i+1))%m; c--; } else ans = (ans*i)%m; } printf("%I64d\n",ans); } return 0; }