#include <cstdio>
#define int long long
#define mod 1000000007
#define maxn 100000
int T, n, k;
int fac[maxn + 5], inv[maxn + 5];

int qkpow( int x, int y ) {
	int ans = 1;
	while( y ) {
		if( y & 1 ) ans = ans * x % mod;
		x = x * x % mod;
		y >>= 1;
	}
	return ans;
}

int C( int n, int m ) {
	if( n <= 0 || n < m ) return 0;
	else return fac[n] * inv[m] % mod * inv[n - m] % mod;
}

signed main() {
	fac[0] = inv[0] = 1;
	for( int i = 1;i <= maxn;i ++ )
		fac[i] = fac[i - 1] * i % mod;
	inv[maxn] = qkpow( fac[maxn], mod - 2 );
	for( int i = maxn - 1;i;i -- )
		inv[i] = inv[i + 1] * ( i + 1 ) % mod;
	scanf( "%lld", &T );
	while( T -- ) {	
		scanf( "%lld %lld", &n, &k );
		int ans = 0;
		for( int i = 1;i <= n;i ++ )
			ans = ( ans + C( n - ( k - 1 ) * ( i - 1 ), i ) * fac[i] % mod * fac[n - i] % mod * inv[n] % mod ) % mod;
		printf( "%lld\n", ( ans + 1 ) % mod );
	}
	return 0;
}