// DZY Loves Partition.cpp #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define LL long long #define lson l, m, rt<<1 #define rson m+1, r, rt<<1|1 #define PI 3.1415926535897932626 #define EXIT exit(0); #define PAUSE system("pause"); #define DEBUG puts("Here is a BUG"); #define SYNC_CLOSE ios::sync_with_stdio(false); #define what_is(x) cout << #x << " is " << x << endl; #define CLEAR(name, init) memset(name, init, sizeof(name)); const double eps = 1e-8; const int MAXN = (int)1e5 + 5; const LL MOD = 1000000007; using namespace std; LL a[MAXN]; int main(int argc, char const *argv[]) { #ifndef ONLINE_JUDGE freopen("D:\\Documents\\Disk_Synchronous\\Programs\\Acm\\input.txt", "r", stdin); #endif int T; cin >> T; while(T--) { LL n, k; cin >> n >> k; if (n < (k+1)*k/2) { puts("-1"); continue; } n -= (k+1)*k/2; for(int i = 0; i < k; i++) { a[i] = i + 1; } while(n > 0) { if (n <= k) { for(int i = 0; i < n; i++) { a[k-i-1]++; } n -= k; } else { LL tmp = n / k; n %= k; for(int i = 0; i < k; i++) { a[i] += tmp; } } } LL res = 1; for(int i = 0; i < k; i++) { res = res * a[i] % MOD; } cout << res << endl; } return 0; }