// // main.cpp // A // // Created by 黄宇凡 on 16/3/19. // Copyright © 2016年 黄宇凡. All rights reserved. // #include #include #include #include using namespace std; const long long mod=1e9+7; long long n,k; int main(int argc, const char * argv[]) { int T; scanf("%d",&T); while(T--){ cin>>n>>k; long long ans=1; long long i=(n*2/k-k+1)/2; while((2*i+k-1)*k/2<=n) i++; while((2*i+k-1)*k/2>n) i--; long long left=n-(2*i+k-1)*k/2; long long first=k-left; if(i<1){ printf("-1\n"); continue; }else{ for(long long j=i;j<=i+first-1;j++){ ans=ans*j%mod; } for(long long j=i+first+1;j<=i+first+left;j++){ ans=ans*j%mod; } } cout<