#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; typedef pair PII; typedef vector VI; typedef vector VPII; typedef pair PLL; typedef pair PIL; typedef pair PLI; typedef double DB; #define pb push_back #define mset(a, b) memset(a, b, sizeof a) #define all(x) (x).begin(), (x).end() #define bit(x) (1 << (x)) #define bitl(x) (1LL << (x)) #define sqr(x) ((x) * (x)) #define sz(x) ((int)(x.size())) #define cnti(x) (__builtin_popcount(x)) #define cntl(x) (__builtin_popcountll(x)) #define clzi(x) (__builtin_clz(x)) #define clzl(x) (__builtin_clzll(x)) #define ctzi(x) (__builtin_ctz(x)) #define ctzl(x) (__builtin_ctzll(x)) #define X first #define Y second #define Error(x) cout << #x << " = " << x << endl template inline void chkmax(T& x, U y) { if (x < y) x = y; } template inline void chkmin(T& x, U y) { if (y < x) x = y; } const int MOD = 1e9 + 7; int A[1000005]; int modExp(int a, int b, int m) { int rlt = 1; for (; b; b /= 2, a = (LL)a * a % m) if (b & 1) rlt = (LL)rlt * a % m; return rlt; } int main() { int tn; for (cin >> tn; tn--; ) { int n, K; scanf("%d%d", &n, &K); if (n < (LL)K * (K + 1) / 2) { puts("-1"); continue; } n -= (LL)K * (K + 1) / 2; int a = n / K; int m = n % K; for (int i = 0; i < K; i++) { if (i < K - m) A[i] = a; else A[i] = a + 1; } int ans = 1; for (int i = 0; i < K; i++) A[i] += i + 1, ans = (LL)ans * A[i] % MOD; printf("%d\n", ans); } return 0; }