#define _CRT_SECURE_NO_WARNINGS #include<cmath> #include<iostream> #include<stdio.h> #include<algorithm> #include<cstring> using namespace std; #define rep(i,t,n) for(int i =(t);i<=(n);++i) #define per(i,n,t) for(int i =(n);i>=(t);--i) #define mmm(a,b) memset(a,b,sizeof(a)) typedef long long ll; const int maxn = 2e6 + 10; const ll mod = 1e9 + 7; int n, m, k; ll inv[maxn], f[maxn], fac[maxn]; ll c[maxn]; long long kpow(long long a, long long n) { long long res = 1; while (n > 0) { if (n & 1)res = res * a%mod; a = a * a%mod; n >>= 1; } return res; } void init() { f[0] = 1; f[1] = 2; fac[0] = fac[1] = 1; inv[1] = 1; rep(i, 2, maxn) { fac[i] = fac[i - 1] * (ll)i % mod; inv[i] = kpow(fac[i], mod - 2); f[i] = (f[i - 1] * f[i - 2]) % mod; //f[i]-1==F[i]==2^fi-1 } } ll C(int n, int m) { if (n < m) return 0ll; if (m == 0 || n == m) return 1ll; if (n - 1 == m || m == 1) return n; return fac[n] * inv[m] % mod * inv[n - m] % mod; } int main() { int t; cin >> t; init(); while (t--) { cin >> n >> k; mmm(c, 0);ll ans = 0; per(g, n, 1) if(n%g==0){ c[g] = C(n / g + k - 1, k - 1); for (int gg = 2 * g; gg <= n; gg += g) {c[g] -= c[gg];if (c[g] < 0)c[g] += mod;} ans += c[g] * (f[g] - 1) % mod;ans %= mod; } ans *= kpow(C(n + k - 1, k - 1), mod - 2);ans %= mod; cout << ans << endl; } } /* */