#include #include #include #include #include #include #include #define LL long long #define Mod 1000000007 using namespace std; const int maxn = 200010; int s[maxn]; const LL mod = 1e9+7; int main() { s[0] = s[1] = 1; for(int i = 2 ; i < 100000 ; i++) s[i] = s[i - 1] * i; int t; LL n,k; scanf("%d",&t); while(t--) { scanf("%I64d %I64d",&n,&k); LL sum = k * (k+1) / 2; if(sum > n) { printf("-1\n"); continue; } LL low = 1; LL high = k; LL add = (n - sum) / k; low += add; high += add; LL m = (n - sum) % k; LL ans = 1; for(int i = low ; i <= high ; i++) { if(i <= high - m) ans = (ans * i) % mod; else ans = (ans * (i + 1))%mod; } printf("%d\n",ans); } return 0; }