#include <bits/stdc++.h> #define ll long long int #define ld long double using namespace std; const ll mod = 1e9 + 7; const ll N = 4e5 + 50; vector<ll> fact(N + 1, 1); ll power(ll x, ll n) { ll ans = 1; while (n != 0) { if (n % 2 == 1) ans = (ans * x) % mod; x = (x * x) % mod; n /= 2; } return ans % mod; } ll nCr(ll n, ll r) { ll x = power(fact[r], mod - 2); ll y = power(fact[n - r], mod - 2); x = (x * y) % mod; return (fact[n] * x) % mod; } void mainSolve() { ll n, m; cin >> n >> m; ll y = (n + m - 1) / m; ll ans = (nCr(n + m, m) - nCr(m + y - 1, m) + mod) % mod; cout << ans << endl; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t; cin >> t; for (ll i = 2; i <= N; i++) fact[i] = (fact[i - 1] * i) % mod; while (t--) { mainSolve(); } return 0; }