#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>usingnamespacestd;
constint N = 1e6 ;
#define LL long longconst LL Mod = 1e9 + 7 ;
LL f [N+10] , fac [N+10] , inv [N+10] ;
void exgcd ( LL a , LL b , LL &d , LL &x , LL &y ){
if ( b == 0 ) {
d = a ;
x = 1 ;
y = 0 ;
return ;
}
exgcd ( b , a%b , d , y , x ) ;
y -= x * ( a/b ) ;
}
LL getinv ( LL a , LL n ){
LL d , x , y ;
exgcd ( a , n , d , x , y ) ;
return ( x+n ) % n ;
}
LL C ( int n , int m ) {
if ( n == 0 || m > n ) return0 ;
return ( fac [n] * inv [m] ) % Mod * inv [n-m] % Mod ;
}
void init (){
fac [0] = 1 ;
for ( int i = 1 ; i <= N + 2 ; ++ i )
fac [i] = ( fac [i-1] * i ) % Mod ;
inv [0] = 1 ;
for ( int i = 1 ; i <= N + 2 ; ++ i )
inv [i] = getinv ( fac [i] , Mod ) ;
f [0] = 1 ;
f [1] = 0 , f [2] = 1;
for ( int i = 3 ; i <= N + 2 ; ++ i ){
f [i] = ( ( f [i-1] + f [i-2] ) % Mod ) * (i-1) % Mod ;
}
}
int main () {
init ();
int T ;
scanf ( "%d" , &T );
while ( T-- ) {
LL a , b ;
scanf ( "%lld%lld" , &a , &b ) ;
printf ( "%lld\n" , C(a,b)*f[a-b]%Mod );
}
return0 ;
}