#include #include #include #include #include #define LL long long #define mmod 1000000007 using namespace std; LL n,k,ans; int main() { int z; scanf("%d",&z); while(z--) { scanf("%I64d%I64d",&n,&k); LL s=(1+k)*k/2; if(s>n) {printf("-1\n");continue;} LL t=n/k,g=n%k; ans=1;LL x=k/2; if(k%2) { for(int i=t+x;i>=t+x-g+1;i--) ans=(ans*(i+1))%mmod; for(int i=t-x;i=t-x;i--) { if(g==0) {y=i;break;} ans=(ans*(i+1))%mmod; g--; } if(y!=-1) for(int i=t-x;i<=y;i++) ans=(ans*i)%mmod; y=-1; for(int i=t+x;i>=t+1;i--) { if(g==0) {y=i;break;} ans=(ans*(i+1))%mmod; g--; } if(y!=-1) for(int i=t+1;i<=y;i++) ans=(ans*i)%mmod; } printf("%I64d\n",ans); } return 0; }