#include #include #include #include #include #define MOD 1000000007 using namespace std; long long ans[100010]; int l; int main() { int T; scanf("%d",&T); while (T --) { int n,k; scanf("%d%d",&n,&k); if (1LL * k * (k + 1) / 2 > n) puts("-1"); else { for (int i = 1;i <= k;i ++) ans[i] = i; n -= (1LL * k * (k + 1) / 2); for (int i = 1;i <= k;i ++) ans[i] += n / k; n %= k; l=k; while (n) ans[l] ++,n --,l --; int res = 1; for (int i = 1;i <= k;i ++) res = 1LL * res * ans[i] % MOD; printf("%d\n",res); } } }