#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define ff first
#define ss second
#define debug(x) cerr<<#x<<" : "<<x<<endl;
#define dbg2(x, y) cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl;
#define dbg3(x, y, z) cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl;
#define debugv(v) for(int i = 0; i<(int)(v.size()); i++){ cerr<<#v<<"["<<i<<"] = "<<v[i]<<endl;}
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define MOD 1000000007
#define BIGMOD 32361122672259149LL

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//functions - find_by_order(index) - returns iterator, order_of_key(key) - number of values less than key
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ll md(ll a) {
	return ((a%MOD)+MOD)%MOD;
}

const int N = 1e5;
ll fact[N+5];
ll invfact[N+5];

ll po(ll a, ll b) {
	if (b==0) return 1ll;
	ll x = po(a, b>>1);
	x = md(x*x);
	if (b&1) x = md(x*a);
	return x;
}

ll modinv(ll a) {
	return po(md(a), MOD-2);
}

ll ncr(ll n, ll r) {
	if (r>n) return 0LL;
	return md(md(fact[n]*invfact[r])*invfact[n-r]);
}

ll ways(ll n, ll f) {

	return ncr(n-1, f-1);
}

void solve() {
	ll n, f;
	scanf("%lld %lld", &n, &f);

	ll ans = ways(n, f);
	// debug(ans);
	for (ll i=2; i*i<=n; i++) {
		if (n%i == 0) {
			// debug(i);

			ans = md(ans-ways(n/i, f));
			if (i*i!=n) ans = md(ans-ways(i, f));
			// debug(ans);
		}
	}

	printf("%lld\n", ans);
}

int main() {
	#ifdef LOCAL
	freopen("i.txt", "r", stdin);
	freopen("o.txt", "w", stdout);
	#endif

	// ios_base::sync_with_stdio(0);
	// cin.tie(0);
	// cout.tie(0);

	fact[0] = 1LL;
	invfact[0] = 1LL;
	for (ll i = 1; i<=N; i++) {
		fact[i] = md(i*fact[i-1]);
		invfact[i] = modinv(fact[i]);
	}
	// cerr << po(2, 4) << ' ' << po(3, 3) << endl;
	// cerr << fact[6] << ' '  << invfact[6] << ' ' << invfact[0] << endl;
	// cerr << ncr(6, 0) << endl;
	// cerr << ncr(6, 1) << endl;
	int num_tests = 1;
	scanf("%d ", &num_tests);
	// cin>>num_tests;

	for (int tc=1; tc<=num_tests; tc++) {
		// printf("Case #%d: ", tc);
		// cout << "Case #" << tc << ": ";
		solve();
	}
	printclock
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define ff first
#define ss second
#define debug(x) cerr<<#x<<" : "<<x<<endl;
#define dbg2(x, y) cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl;
#define dbg3(x, y, z) cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl;
#define debugv(v) for(int i = 0; i<(int)(v.size()); i++){ cerr<<#v<<"["<<i<<"] = "<<v[i]<<endl;}
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define MOD 1000000007
#define BIGMOD 32361122672259149LL

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//functions - find_by_order(index) - returns iterator, order_of_key(key) - number of values less than key
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ll md(ll a) {
	return ((a%MOD)+MOD)%MOD;
}

const int N = 1e5;
ll fact[N+5];
ll invfact[N+5];

ll po(ll a, ll b) {
	if (b==0) return 1ll;
	ll x = po(a, b>>1);
	x = md(x*x);
	if (b&1) x = md(x*a);
	return x;
}

ll modinv(ll a) {
	return po(md(a), MOD-2);
}

ll ncr(ll n, ll r) {
	if (r>n) return 0LL;
	return md(md(fact[n]*invfact[r])*invfact[n-r]);
}

ll ways(ll n, ll f) {

	return ncr(n-1, f-1);
}

ll solve(ll n, ll f) {

	if (f>n) return 0ll;
	if (f==1) {
		if (n>1) {
			return 0;
		} else {
			return 1;
		}
	}
	ll ans = ways(n, f);
	// debug(ans);
	for (ll i=2; i*i<=n; i++) {
		if (n%i == 0) {
			// debug(i);

			ans = md(ans-solve(n/i, f));
			if (i*i!=n) ans = md(ans-solve(i, f));
			// debug(ans);
		}
	}

	return ans;
}

int main() {
	#ifdef LOCAL
	freopen("i.txt", "r", stdin);
	freopen("o.txt", "w", stdout);
	#endif

	// ios_base::sync_with_stdio(0);
	// cin.tie(0);
	// cout.tie(0);

	fact[0] = 1LL;
	invfact[0] = 1LL;
	for (ll i = 1; i<=N; i++) {
		fact[i] = md(i*fact[i-1]);
		invfact[i] = modinv(fact[i]);
	}
	// cerr << po(2, 4) << ' ' << po(3, 3) << endl;
	// cerr << fact[6] << ' '  << invfact[6] << ' ' << invfact[0] << endl;
	// cerr << ncr(6, 0) << endl;
	// cerr << ncr(6, 1) << endl;
	int num_tests = 1;
	scanf("%d ", &num_tests);
	// cin>>num_tests;

	for (int tc=1; tc<=num_tests; tc++) {
		// printf("Case #%d: ", tc);
		// cout << "Case #" << tc << ": ";
		ll n, f;
		scanf("%lld %lld", &n, &f);
		printf("%lld\n", solve(n, f));
	}
	printclock
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define ff first
#define ss second
#define debug(x) cerr<<#x<<" : "<<x<<endl;
#define dbg2(x, y) cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl;
#define dbg3(x, y, z) cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl;
#define debugv(v) for(int i = 0; i<(int)(v.size()); i++){ cerr<<#v<<"["<<i<<"] = "<<v[i]<<endl;}
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define MOD 1000000007
#define BIGMOD 32361122672259149LL

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//functions - find_by_order(index) - returns iterator, order_of_key(key) - number of values less than key
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ll md(ll a) {
	return ((a%MOD)+MOD)%MOD;
}

const int N = 1e5;
ll fact[N+5];
ll invfact[N+5];

ll po(ll a, ll b) {
	if (b==0) return 1ll;
	ll x = po(a, b>>1);
	x = md(x*x);
	if (b&1) x = md(x*a);
	return x;
}

ll modinv(ll a) {
	return po(md(a), MOD-2);
}

ll ncr(ll n, ll r) {
	if (r>n) return 0LL;
	return md(md(fact[n]*invfact[r])*invfact[n-r]);
}

ll ways(ll n, ll f) {

	return ncr(n-1, f-1);
}

void solve() {
	ll n, f;
	scanf("%lld %lld", &n, &f);

	if (f==1) {
		if (n>1) {
			printf("0\n");
		} else {
			printf("1\n");
		}
		return;
	}
	ll ans = ways(n, f);
	// debug(ans);
	for (ll i=2; i*i<=n; i++) {
		if (n%i == 0) {
			// debug(i);

			ans = md(ans-ways(n/i, f));
			if (i*i!=n) ans = md(ans-ways(i, f));
			// debug(ans);
		}
	}

	printf("%lld\n", ans);
}

int main() {
	#ifdef LOCAL
	freopen("i.txt", "r", stdin);
	freopen("o.txt", "w", stdout);
	#endif

	// ios_base::sync_with_stdio(0);
	// cin.tie(0);
	// cout.tie(0);

	fact[0] = 1LL;
	invfact[0] = 1LL;
	for (ll i = 1; i<=N; i++) {
		fact[i] = md(i*fact[i-1]);
		invfact[i] = modinv(fact[i]);
	}
	// cerr << po(2, 4) << ' ' << po(3, 3) << endl;
	// cerr << fact[6] << ' '  << invfact[6] << ' ' << invfact[0] << endl;
	// cerr << ncr(6, 0) << endl;
	// cerr << ncr(6, 1) << endl;
	int num_tests = 1;
	scanf("%d ", &num_tests);
	// cin>>num_tests;

	for (int tc=1; tc<=num_tests; tc++) {
		// printf("Case #%d: ", tc);
		// cout << "Case #" << tc << ": ";
		solve();
	}
	printclock
	return 0;
}


#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int lli;
const lli mod = 1e9 + 7;
const int MM = 1e5 + 234;
lli powmod(lli a1,lli b1,lli modx = mod) {lli res=1; a1%=modx; for(;b1;b1>>=1) {if(b1&1)res=res*a1%modx; a1=(a1*a1)%modx;}return res;}
lli inv(lli ax,lli modx = mod) { return powmod(ax,modx-2,modx); }
lli fac[MM], ifac[MM];
void preFac(lli modx = mod)
{
    fac[0] = 1;
    ifac[0] = 1;
    for(int i = 1; i < MM; i++) {
        fac[i] = (i * fac[i-1]) % modx;
    }
    ifac[MM - 1] = inv(fac[MM - 1]);
    for(int i = MM - 2; i >= 0; i--) {
    	ifac[i] = ((i + 1) * ifac[i + 1]) % mod;
    }
}
lli nCr(lli N, lli R, lli modx = mod)
{
    if(R <= N && R >=0) {
        return ((fac[N] * ifac[R])%modx * ifac[N-R])%modx;
    }
	return 0;
}
const lli N = 110000;
bool prim[N];
int mob[N];

void Mobius()
{
    for(int i=1; i<N; i++) {
        prim[i] = 1;
    }
    for(int i=2; i<sqrt(N)+2; i++) {
        if(prim[i] == 1) {
           for(int j=i*i; j<N; j += i) {
                prim[j] = 0;
           }
        }
    }
    for(int i = 1; i < N; i++) {
    	mob[i] = 1;
    }
    for(int i = 2; i < N; i++) {
    	if(!prim[i]) {
    		continue;
    	}
    	if((lli)i * i < N) {
    		for(int j = i * i; j < N; j += i * i) {
    			mob[j] = 0;
    		}
    	}
    	for(int j = i; j < N; j += i) {
    		mob[j] *= -1;
    	}
    }
}

lli solve(int N, int K) {
	lli ans = 0;
	for(int i = 1; i * i <= N; i++) {
		// cout << mob[i] << " " << i << endl;
		if(N % i == 0 && mob[i]) {
			ans += mob[i] * nCr(N / i - 1, K - 1);
			ans += mod;
			ans %= mod;
		}
		if(i * i != N && N % i == 0 && mob[N / i]) {
			ans += mob[N / i] * nCr(i - 1, K - 1);
			ans += mod;
			ans %= mod;
		}

	}
	return ans;
}

int main() {fio; // remove during scanf
	preFac();
	Mobius();
	int M;
	cin >> M;
	while(M--) {
		int N, K;
		cin >> N >> K;
		cout << solve(N, K) << '\n';
	}

    return 0;
}


#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int lli;
const lli mod = 1e9 + 7;
const int MM = 1e5 + 234;
lli powmod(lli a1,lli b1,lli modx = mod) {lli res=1; a1%=modx; for(;b1;b1>>=1) {if(b1&1)res=res*a1%modx; a1=(a1*a1)%modx;}return res;}
lli inv(lli ax,lli modx = mod) { return powmod(ax,modx-2,modx); }
lli fac[MM], ifac[MM];
void preFac(lli modx = mod)
{
    fac[0] = 1;
    ifac[0] = 1;
    for(int i = 1; i < MM; i++) {
        fac[i] = (i * fac[i-1]) % modx;
        ifac[i] = inv(fac[i], modx);
    }
}
lli nCr(lli N, lli R, lli modx = mod)
{
    if(R <= N && R >=0) {
        return ((fac[N] * ifac[R])%modx * ifac[N-R])%modx;
    }
	return 0;
}
const lli N = 110000;
bool prim[N];
int mob[N];

void Mobius()
{
    for(int i=1; i<N; i++) {
        prim[i] = 1;
    }
    for(int i=2; i<sqrt(N)+2; i++) {
        if(prim[i] == 1) {
           for(int j=i*i; j<N; j += i) {
                prim[j] = 0;
           }
        }
    }
    for(int i = 1; i < N; i++) {
    	mob[i] = 1;
    }
    for(int i = 2; i < N; i++) {
    	if(!prim[i]) {
    		continue;
    	}
    	if((lli)i * i < N) {
    		for(int j = i * i; j < N; j += i * i) {
    			mob[j] = 0;
    		}
    	}
    	for(int j = i; j < N; j += i) {
    		mob[j] *= -1;
    	}
    }
}

lli solve(int N, int K) {
	lli ans = 0;
	for(int i = 1; i * i <= N; i++) {
		// cout << mob[i] << " " << i << endl;
		if(N % i == 0 && mob[i]) {
			ans += mob[i] * nCr(N / i - 1, K - 1);
			ans %= mod;
		}
		if(i * i != N && N % i == 0 && mob[N / i]) {
			ans += mob[N / i] * nCr(i - 1, K - 1);
		}
	}
	return ans;
}

int main() {fio; // remove during scanf
	preFac();
	Mobius();
	int M;
	cin >> M;
	while(M--) {
		int N, K;
		cin >> N >> K;
		cout << solve(N, K) << '\n';
	}

    return 0;
}


#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int lli;
const lli mod = 1e9 + 7;
const int MM = 1e5 + 234;
lli powmod(lli a1,lli b1,lli modx = mod) {lli res=1; a1%=modx; for(;b1;b1>>=1) {if(b1&1)res=res*a1%modx; a1=(a1*a1)%modx;}return res;}
lli inv(lli ax,lli modx = mod) { return powmod(ax,modx-2,modx); }
lli fac[MM], ifac[MM];
void preFac(lli modx = mod)
{
    fac[0] = 1;
    ifac[0] = 1;
    for(int i = 1; i < MM; i++) {
        fac[i] = (i * fac[i-1]) % modx;
        ifac[i] = inv(fac[i], modx);
    }
}
lli nCr(lli N, lli R, lli modx = mod)
{
    if(R <= N && R >=0) {
        return ((fac[N] * ifac[R])%modx * ifac[N-R])%modx;
    }
	return 0;
}
const lli N = 110000;
bool prim[N];
int mob[N];

void Mobius()
{
    for(int i=1; i<N; i++) {
        prim[i] = 1;
    }
    for(int i=2; i<sqrt(N)+2; i++) {
        if(prim[i] == 1) {
           for(int j=i*i; j<N; j += i) {
                prim[j] = 0;
           }
        }
    }
    for(int i = 1; i < N; i++) {
    	mob[i] = 1;
    }
    for(int i = 2; i < N; i++) {
    	if(!prim[i]) {
    		continue;
    	}
    	if((lli)i * i < N) {
    		for(int j = i * i; j < N; j += i * i) {
    			mob[j] = 0;
    		}
    	}
    	for(int j = i; j < N; j += i) {
    		mob[j] *= -1;
    	}
    }
}

lli solve(int N, int K) {
	lli ans = 0;
	for(int i = 1; i * i <= N; i++) {
		// cout << mob[i] << " " << i << endl;
		if(N % i == 0 && mob[i]) {
			ans += mob[i] * nCr(N / i - 1, K - 1);
			ans %= mod;
		}
		if(i * i != N && N % i == 0 && mob[N / i]) {
			ans += mob[N / i] * nCr(i - 1, K - 1);
			ans %= mod;
		}

	}
	return ans;
}

int main() {fio; // remove during scanf
	preFac();
	Mobius();
	int M;
	cin >> M;
	while(M--) {
		int N, K;
		cin >> N >> K;
		cout << solve(N, K) << '\n';
	}

    return 0;
}


#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int lli;
const lli mod = 1e9 + 7;
const int MM = 1e5 + 234;
lli powmod(lli a1,lli b1,lli modx = mod) {lli res=1; a1%=modx; for(;b1;b1>>=1) {if(b1&1)res=res*a1%modx; a1=(a1*a1)%modx;}return res;}
lli inv(lli ax,lli modx = mod) { return powmod(ax,modx-2,modx); }
lli fac[MM], ifac[MM];
void preFac(lli modx = mod)
{
    fac[0] = 1;
    ifac[0] = 1;
    for(int i = 1; i < MM; i++) {
        fac[i] = (i * fac[i-1]) % modx;
        ifac[i] = inv(fac[i], modx);
    }
}
lli nCr(lli N, lli R, lli modx = mod)
{
    if(R <= N && R >=0) {
        return ((fac[N] * ifac[R])%modx * ifac[N-R])%modx;
    }
	return 0;
}
const lli N = 110000;
bool prim[N];
int mob[N];

void Mobius()
{
    for(int i=1; i<N; i++) {
        prim[i] = 1;
    }
    for(int i=2; i<sqrt(N)+2; i++) {
        if(prim[i] == 1) {
           for(int j=i*i; j<N; j += i) {
                prim[j] = 0;
           }
        }
    }
    for(int i = 1; i < N; i++) {
    	mob[i] = 1;
    }
    for(int i = 2; i < N; i++) {
    	if(!prim[i]) {
    		continue;
    	}
    	if((lli)i * i < N) {
    		for(int j = i * i; j < N; j += i * i) {
    			mob[j] = 0;
    		}
    	}
    	for(int j = i; j < N; j += i) {
    		mob[j] *= -1;
    	}
    }
}

lli solve(int N, int K) {
	lli ans = 0;
	for(int i = 1; i * i <= N; i++) {
		// cout << mob[i] << " " << i << endl;
		if(N % i == 0 && mob[i]) {
			ans += mob[i] * nCr(N / i - 1, K - 1);
			ans += mod;
			ans %= mod;
		}
		if(i * i != N && N % i == 0 && mob[N / i]) {
			ans += mob[N / i] * nCr(i - 1, K - 1);
			ans += mod;
			ans %= mod;
		}

	}
	return ans;
}

int main() {fio; // remove during scanf
	preFac();
	Mobius();
	int M;
	cin >> M;
	while(M--) {
		int N, K;
		cin >> N >> K;
		cout << solve(N, K) << '\n';
	}

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
using ll = long long; using ld = long double; const char nl = '\n';
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */

#include <bits/extc++.h>
namespace pbds =  __gnu_pbds;
template <typename key, typename val=pbds::null_type, typename comp=less<key>>
using ostree=pbds::tree<key,val,comp,pbds::rb_tree_tag,pbds::tree_order_statistics_node_update>;
using vi = vector< int >; using vll = vector< ll >;
#define all(x) std::begin(x), std::end(x)
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename...Args, template<typename...> typename T> string to_string(T<Args...> const&);
string to_string(string const&s){return '"'+s+'"';}
string to_string(char const &c) {return to_string(string(1,c));}
string to_string(char const *c) {return to_string(string(c));}
string to_string(bool const &b) {return (b ? "1" : "0");}
template<typename... Args> string to_string(pair<Args...> const&p)
{return "("+to_string(p.first)+", "+to_string(p.second)+")";}
template <typename...Args, template<typename...> typename T> string to_string(T<Args...> const&S)
{string s = "{"; for(auto const& e: S)s+=" "+to_string(e);s+=" }"; return s;}
template<typename Tail> void debug_out(Tail t) {cerr<<" "<<to_string(t)<<" ]"<<endl;}
template<typename Head, typename... Tail> void debug_out(Head h, Tail... t)
{cerr << " " << to_string(h) << ","; debug_out(t...);}
#define pr(...) cerr<<"["<<(#__VA_ARGS__)<<"] : [", debug_out(__VA_ARGS__)
template <typename T> void dbr(T lb, T ub)
{cerr<<'{';for(auto it=lb; it!=ub; it++)cerr<<' '<<to_string(*it); cerr<<" }"<<endl;}
template<typename T, typename Comp=less<T>> bool smin(T &mem, T const&v, Comp const&cmp=Comp())
{return cmp(v, mem) ? mem = v, true : false;}
template<typename T, typename Comp=less<T>> bool smax(T &mem, T const&v, Comp const&cmp=Comp())
{return cmp(mem, v) ? mem = v, true : false;}
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */

int const N = 100100;
ll const mod = 7+(ll)1e9;
ll fac[N], ifac[N], minv[N];
vector<int> divs[N];

ll nck(int n, int k) {
  if( k < 0 or k > n ) return 0;
  ll ret = ( fac[n] * ifac[k] ) % mod;
  return (ret * ifac[n-k]) % mod;
}

int n, f;

int main() {
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  minv[1] = 1;
  for(ll i=2; i<N; i++) minv[i] = mod - ( (mod/i) * minv[mod%i] ) % mod;
  fac[0] = ifac[0] = 1;
  for(ll i=1; i<N; i++) fac[i] = (fac[i-1] * i)%mod;
  for(ll i=1; i<N; i++) ifac[i] = (ifac[i-1] * minv[i])%mod;

  for(int i=2; i<N; i++)
    for(int j=i; j<N; j+=i) divs[j].emplace_back(i);

  int q; cin >> q;
  while(q--) {
    cin >> n >> f;
    if( f == 1 ) {
      cout << (n==1 ? 1 : 0) << nl;
      continue;
    }

    unordered_map<int, ll> dp;
    dp[1] = 0;
    for(int d: divs[n]) {
      ll temp = nck(d-1, f-1);
      for(int dd: divs[d]) {
        temp -= dp[dd];
        if( temp < 0 ) temp += mod;
      }
      dp[d] = temp;
    }
    cout << dp[n] << nl;
  }

}
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */


#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
using ll = long long; using ld = long double; const char nl = '\n';
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */

#include <bits/extc++.h>
namespace pbds =  __gnu_pbds;
template <typename key, typename val=pbds::null_type, typename comp=less<key>>
using ostree=pbds::tree<key,val,comp,pbds::rb_tree_tag,pbds::tree_order_statistics_node_update>;
using vi = vector< int >; using vll = vector< ll >;
#define all(x) std::begin(x), std::end(x)
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename...Args, template<typename...> typename T> string to_string(T<Args...> const&);
string to_string(string const&s){return '"'+s+'"';}
string to_string(char const &c) {return to_string(string(1,c));}
string to_string(char const *c) {return to_string(string(c));}
string to_string(bool const &b) {return (b ? "1" : "0");}
template<typename... Args> string to_string(pair<Args...> const&p)
{return "("+to_string(p.first)+", "+to_string(p.second)+")";}
template <typename...Args, template<typename...> typename T> string to_string(T<Args...> const&S)
{string s = "{"; for(auto const& e: S)s+=" "+to_string(e);s+=" }"; return s;}
template<typename Tail> void debug_out(Tail t) {cerr<<" "<<to_string(t)<<" ]"<<endl;}
template<typename Head, typename... Tail> void debug_out(Head h, Tail... t)
{cerr << " " << to_string(h) << ","; debug_out(t...);}
#define pr(...) cerr<<"["<<(#__VA_ARGS__)<<"] : [", debug_out(__VA_ARGS__)
template <typename T> void dbr(T lb, T ub)
{cerr<<'{';for(auto it=lb; it!=ub; it++)cerr<<' '<<to_string(*it); cerr<<" }"<<endl;}
template<typename T, typename Comp=less<T>> bool smin(T &mem, T const&v, Comp const&cmp=Comp())
{return cmp(v, mem) ? mem = v, true : false;}
template<typename T, typename Comp=less<T>> bool smax(T &mem, T const&v, Comp const&cmp=Comp())
{return cmp(mem, v) ? mem = v, true : false;}
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */

int const N = 100100;
ll const mod = 7+(ll)1e9;
ll fac[N], ifac[N], minv[N];
vector<int> divs[N];

ll nck(int n, int k) {
  if( k < 0 or k > n ) return 0;
  ll ret = ( fac[n] * ifac[k] ) % mod;
  return (ret * ifac[n-k]) % mod;
}

int n, f;

int main() {
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  minv[1] = 1;
  for(ll i=2; i<N; i++) minv[i] = mod - ( (mod/i) * minv[mod%i] ) % mod;
  fac[0] = ifac[0] = 1;
  for(ll i=1; i<N; i++) fac[i] = (fac[i-1] * i)%mod;
  for(ll i=1; i<N; i++) ifac[i] = (ifac[i-1] * minv[i])%mod;

  for(int i=2; i<N; i++)
    for(int j=i; j<N; j+=i) divs[j].emplace_back(i);

  int q; cin >> q;
  while(q--) {
    cin >> n >> f;
    if( n == 1 and f == 1 ) {
      cout << 1 << nl;
      continue;
    }

    unordered_map<int, ll> dp;
    dp[1] = 0;
    for(int d: divs[n]) {
      ll temp = nck(d-1, f-1);
      for(int dd: divs[d]) {
        temp -= dp[dd];
        if( temp < 0 ) temp += mod;
      }
      dp[d] = temp;
    }
    cout << dp[n] << nl;
  }

}
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */


#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <queue>
#include <cassert>
#include <string>
#include <map>
#define MOD 1000000007
using namespace std;

map<pair<int,int>, int> dp;

vector<int> factors[100010];
long long fact[100010], ifact[100010];

long long ncr(int n, int r) {
	if (n < r || n <= 0 || r < 0) return 0;
	return (fact[n] * ifact[r] % MOD)*ifact[n - r] % MOD;
}
long long calc(int f, int n) {
	auto p = make_pair(f, n);
	if (dp.count(p) != 0) return dp[p];
	long long total = ncr(n - 1, f - 1);
	for (auto fac : factors[n]) total = (MOD + total - calc(f, n / fac)) % MOD;
	return dp[p] = total;
}

int main() {
	fact[0] = fact[1] = 1;
	for (int i = 2; i < 100010; i++) fact[i] = fact[i - 1] * i % MOD;
	ifact[0] = ifact[1] = 1;
	for (int i = 2; i < 100010; i++) ifact[i] = (MOD - (MOD / i)*ifact[MOD%i] % MOD) % MOD;
	for (int i = 2; i < 100010; i++) ifact[i] = ifact[i - 1] * ifact[i] % MOD;
	for (int i = 2; i < 100010; i++) for (int j = 2 * i; j < 100010; j += i) factors[j].push_back(i);

	int Q; cin >> Q;
	for (int i = 0; i < Q; i++) {
		int n, f; cin >> n >> f;
		cout << calc(f, n) << endl;
	}
}


#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <queue>
#include <cassert>
#include <string>
#include <map>
#define MOD 1000000007
using namespace std;

map<pair<int,int>, int> dp;

vector<int> factors[100010];
long long fact[100010], ifact[100010];

long long ncr(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	return (fact[n] * ifact[r] % MOD)*ifact[n - r] % MOD;
}
long long calc(int f, int n) {
	auto p = make_pair(f, n);
	if (dp.count(p) != 0) return dp[p];
	long long total = ncr(n - 1, f - 1);
	for (auto fac : factors[n]) total = (MOD + total - calc(f, n / fac)) % MOD;
	return dp[p] = (f == 1 ? (n == 1 ? total : 0) : total);
}

int main() {
	ios_base::sync_with_stdio(false);
	fact[0] = fact[1] = 1;
	for (int i = 2; i < 100010; i++) fact[i] = fact[i - 1] * i % MOD;
	ifact[0] = ifact[1] = 1;
	for (int i = 2; i < 100010; i++) ifact[i] = (MOD - (MOD / i)*ifact[MOD%i] % MOD) % MOD;
	for (int i = 2; i < 100010; i++) ifact[i] = ifact[i - 1] * ifact[i] % MOD;
	for (int i = 2; i < 100010; i++) for (int j = 2 * i; j < 100010; j += i) factors[j].push_back(i);

	int Q; cin >> Q;
	for (int i = 0; i < Q; i++) {
		int n, f; cin >> n >> f;
		dp.clear();
		cout << calc(f, n) << endl;
	}
}


#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <queue>
#include <cassert>
#include <string>
#include <map>
#define MOD 1000000007
using namespace std;

map<pair<int,int>, int> dp;

vector<int> factors[100010];
long long fact[100010], ifact[100010];

long long ncr(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	return (fact[n] * ifact[r] % MOD)*ifact[n - r] % MOD;
}
long long calc(int f, int n) {
	auto p = make_pair(f, n);
	if (dp.count(p) != 0) return dp[p];
	long long total = ncr(n - 1, f - 1);
	for (auto fac : factors[n]) total = (MOD + total - calc(f, n / fac)) % MOD;
	return dp[p] = (f == 1 ? (n == 1 ? total : 0) : total);
}

int main() {
	fact[0] = fact[1] = 1;
	for (int i = 2; i < 100010; i++) fact[i] = fact[i - 1] * i % MOD;
	ifact[0] = ifact[1] = 1;
	for (int i = 2; i < 100010; i++) ifact[i] = (MOD - (MOD / i)*ifact[MOD%i] % MOD) % MOD;
	for (int i = 2; i < 100010; i++) ifact[i] = ifact[i - 1] * ifact[i] % MOD;
	for (int i = 2; i < 100010; i++) for (int j = 2 * i; j < 100010; j += i) factors[j].push_back(i);

	int Q; cin >> Q;
	for (int i = 0; i < Q; i++) {
		int n, f; cin >> n >> f;
		cout << calc(f, n) << endl;
	}
}


#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <queue>
#include <cassert>
#include <string>
#include <map>
#define MOD 1000000007
using namespace std;

int dp[100010];
vector<int> factors[100010];
long long fact[100010], ifact[100010];

long long ncr(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	return (fact[n] * ifact[r] % MOD)*ifact[n - r] % MOD;
}
long long calc(int f, int n) {
	if (dp[n] != -1) return dp[n];
	long long total = ncr(n - 1, f - 1);
	for (auto fac : factors[n]) total = (MOD + total - calc(f, n / fac)) % MOD;
	return dp[n] = (f == 1 ? (n == 1 ? total : 0) : total);
}

int main() {
	ios_base::sync_with_stdio(false);
	fact[0] = fact[1] = 1;
	for (int i = 2; i < 100010; i++) fact[i] = fact[i - 1] * i % MOD;
	ifact[0] = ifact[1] = 1;
	for (int i = 2; i < 100010; i++) ifact[i] = (MOD - (MOD / i)*ifact[MOD%i] % MOD) % MOD;
	for (int i = 2; i < 100010; i++) ifact[i] = ifact[i - 1] * ifact[i] % MOD;
	for (int i = 2; i < 100010; i++) for (int j = 2 * i; j < 100010; j += i) factors[j].push_back(i);

	int Q; cin >> Q;
	for (int i = 0; i < Q; i++) {
		int n, f; cin >> n >> f;
		dp[n] = dp[1] = -1;
		for (auto x : factors[n]) dp[x] = -1;
		cout << calc(f, n) << endl;
	}
}


#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <queue>
#include <cassert>
#include <string>
#include <map>
#define MOD 1000000007
using namespace std;

map<int, int> dp[100010];

vector<int> factors[100010];
long long fact[100010], ifact[100010];

long long ncr(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	return (fact[n] * ifact[r] % MOD)*ifact[n - r] % MOD;
}
long long calc(int f, int n) {
	if (dp[n].count(f) != 0) return dp[n][f];
	long long total = ncr(n - 1, f - 1);
	for (auto fac : factors[n]) total = (MOD + total - calc(f, n / fac)) % MOD;
	return dp[n][f] = (f == 1 ? (n == 1 ? total : 0) : total);
}

int main() {
	ios_base::sync_with_stdio(false);
	fact[0] = fact[1] = 1;
	for (int i = 2; i < 100010; i++) fact[i] = fact[i - 1] * i % MOD;
	ifact[0] = ifact[1] = 1;
	for (int i = 2; i < 100010; i++) ifact[i] = (MOD - (MOD / i)*ifact[MOD%i] % MOD) % MOD;
	for (int i = 2; i < 100010; i++) ifact[i] = ifact[i - 1] * ifact[i] % MOD;
	for (int i = 2; i < 100010; i++) for (int j = 2 * i; j < 100010; j += i) factors[j].push_back(i);

	int Q; cin >> Q;
	for (int i = 0; i < Q; i++) {
		int n, f; cin >> n >> f;
		cout << calc(f, n) << endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)

int mod = 1000000007;
int add(int x, int y) { return (x += y) >= mod ? x - mod : x; }
template<class... T> int add(int x, T... y) { return add(x, add(y...)); }
int mul(int x, int y) { return 1LL * x * y % mod; }
template<class... T> int mul(int x, T... y) { return mul(x, mul(y...)); }
int sub(int x, int y) { return add(x, mod - y); }
int modpow(int a, long long b) { int ret = 1; while (b > 0) { if (b & 1) ret = 1LL * ret * a % mod; a = 1LL * a * a % mod; b >>= 1; } return ret; }
int modinv(int a) { return modpow(a, mod - 2); }
int fac[201010], ifac[201010];
void initfac() { fac[0] = ifac[0] = 1; rep(i, 1, 201010) ifac[i] = modinv(fac[i] = mul(i, fac[i - 1])); }
int aCb(int a, int b) { if (b < 0 || a < b) return 0; return mul(fac[a], ifac[a - b], ifac[b]); }
//-----------------------------------------------------------------------------------
int Q, N[101010], F[101010];
int dfs(int n, int f) {
    if (n < f) return 0;
    if (f == n) return 1;

    int res = aCb(n - 1, f - 1);
    for (int i = 2; i*i <= n; i++) if (n % i == 0) {
        res = sub(res, dfs(n/i, f));
    }
    res = sub(res, dfs(1, f));
    return res;
}
//-----------------------------------------------------------------------------------
int main() {
    initfac();

    cin >> Q;
    rep(i, 0, Q) scanf("%d%d", &N[i], &F[i]);

    rep(i, 0, Q) printf("%d\n", dfs(N[i], F[i]));
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
ll power(ll a,ll b, ll m=MOD)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
            res=(res*a)%m;
        a=(a*a)%m;
        b>>=1;
    }
    return res;
}
ll inverse(ll a,ll m=MOD)
{
    return power(a,m-2,m);
}
#define INFl 1e18
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<long long>
#define vvl vector<vl>
#define ii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define forl(i,n) for(int i=0;i<n;i++)
#define fore(i,n) for(int i=1;i<=n;i++)
#define rforl(i,n)  for(int i=n-1;i>=0;i--)
#define rfore(i,n)  for(int i=n;i>=1;i--)
#define INF 1100000009
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define print(x)    for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; printf("\n");
#define printii(x)  for(auto it=x.begin();it!=x.end();it++) printf("%d %d\n",it->F,it->S);
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
vi primes,is_comp,pi;
const int maxn=200005;
ll f[maxn],invf[maxn];
void precalc()
{
    f[0]=1;
    for(int i=1;i<maxn;i++)
        f[i]=(f[i-1]*i)%MOD;
    for(int i=0;i<maxn;i++)
        invf[i]=power(f[i],MOD-2);
}
ll nCr(int n,int r)
{
    if(n<r || n<0 || r<0)
        return 0;
    ll res=f[n]*invf[n-r];
    res%=MOD;
    res*=invf[r];
    res%=MOD;
    return res;
}
void sieve(int mx)
{
    pi.assign(mx,1);
    is_comp.assign(mx,0);
    for(int i=2;i<mx;i++)
    {
        if(!is_comp[i])
        {
            primes.pb(i);
            pi[i]=-1;
        }
        for(int j=0;j<primes.size()&&primes[j]*i<mx;j++)
        {
            is_comp[i*primes[j]]=1;
            pi[i*primes[j]]=pi[i]*pi[primes[j]];
            if(i%primes[j]==0)
            {
                pi[i*primes[j]]=0;
                break;
            }
        }
    }
}
int main()
{
    sieve(100001);
    precalc();
    int q;
    cin>>q;
    while(q--)
    {
        int n,f;
        cin>>f>>n;
        ll ans=0;
        for(int i=1;i*i<=f;i++)
        {
            if(f%i) continue;
            ans+=pi[i]*nCr((f/i)-1,n-1);
            ans%=MOD;
            if(f!=i*i)
            {
                ans+=pi[i]*nCr(i-1,n-1);
                ans%=MOD;
            }
            if(ans<0)   ans+=MOD;
        }
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
ll power(ll a,ll b, ll m=MOD)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
            res=(res*a)%m;
        a=(a*a)%m;
        b>>=1;
    }
    return res;
}
ll inverse(ll a,ll m=MOD)
{
    return power(a,m-2,m);
}
#define INFl 1e18
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<long long>
#define vvl vector<vl>
#define ii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define forl(i,n) for(int i=0;i<n;i++)
#define fore(i,n) for(int i=1;i<=n;i++)
#define rforl(i,n)  for(int i=n-1;i>=0;i--)
#define rfore(i,n)  for(int i=n;i>=1;i--)
#define INF 1100000009
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define print(x)    for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; printf("\n");
#define printii(x)  for(auto it=x.begin();it!=x.end();it++) printf("%d %d\n",it->F,it->S);
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
vi primes,is_comp,pi;
const int maxn=200005;
ll f[maxn],invf[maxn];
void precalc()
{
    f[0]=1;
    for(int i=1;i<maxn;i++)
        f[i]=(f[i-1]*i)%MOD;
    for(int i=0;i<maxn;i++)
        invf[i]=power(f[i],MOD-2);
}
ll nCr(int n,int r)
{
    if(n<r || n<0 || r<0)
        return 0;
    ll res=f[n]*invf[n-r];
    res%=MOD;
    res*=invf[r];
    res%=MOD;
    return res;
}
void sieve(int mx)
{
    pi.assign(mx,1);
    is_comp.assign(mx,0);
    for(int i=2;i<mx;i++)
    {
        if(!is_comp[i])
        {
            primes.pb(i);
            pi[i]=-1;
        }
        for(int j=0;j<primes.size()&&primes[j]*i<mx;j++)
        {
            is_comp[i*primes[j]]=1;
            pi[i*primes[j]]=pi[i]*pi[primes[j]];
            if(i%primes[j]==0)
            {
                pi[i*primes[j]]=0;
                break;
            }
        }
    }
}
int main()
{
    sieve(100001);
    precalc();
    int q;
    cin>>q;
    while(q--)
    {
        int n,f;
        cin>>f>>n;
        ll ans=0;
        for(int i=1;i*i<=f;i++)
        {
            if(f%i) continue;
            ans+=pi[i]*nCr((f/i)-1,n-1);
            ans%=MOD;
            if(f!=i*i)
            {
                ans+=pi[f/i]*nCr(i-1,n-1);
                ans%=MOD;
            }
            if(ans<0)   ans+=MOD;
        }
        cout<<ans<<endl;
    }
}


/*program by mangoyang*/
#include<bits/stdc++.h>
#define inf (0x7f7f7f7f)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
typedef long long ll;
using namespace std;
template <class T>
inline void read(T &x){
    int f = 0, ch = 0; x = 0;
    for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = 1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    if(f) x = -x;
}
#define int ll

const int N = 200005, Mod = 1000000007;
int js[N], mu[N], b[N], prime[N], inv[N], tot, n, m;

inline int Pow(int a, int b){
    int ans = 1;
    for(; b; b >>= 1, a = a * a % Mod)
        if(b & 1) ans = ans * a % Mod;
    return ans;
}
inline void Prework(){
    mu[1] = 1, js[0] = 1, inv[0] = 1;
    for(int i = 1; i < N; i++)
        js[i] = js[i-1] * i % Mod, inv[i] = Pow(js[i], Mod - 2);
    for(int i = 2; i < N; i++){
        if(!b[i]) prime[++tot] = i, mu[i] = -1;
        for(int j = 1; j <= tot && i * prime[j] < N; j++){
            b[i*prime[j]] = 1;
            if(i % prime[j]) mu[i*prime[j]] = -mu[i]; else break;
        }
    }
}

inline int C(int n, int i){ return js[n] * inv[i] % Mod * inv[n-i] % Mod; }
inline int calc(int x){ return x < m ? 0 : C(x - 1, m - 1) * mu[n/x] % Mod; }

inline void solve(){
    int ans = 0; read(n), read(m);
    int num = (int) sqrt(n);
    for(int i = 1; i <= num; i++) if(n % i == 0){
        int x = i, y = n / i;
        (ans += calc(x)) %= Mod;
        //cout << y << " " << calc(x) << endl;
        if(x != y) (ans += calc(y)) %= Mod;
    }
    printf("%lld\n", ans);
}

signed main(){
    Prework();
    int T; read(T); while(T--) solve();
    return 0;
}


/*program by mangoyang*/
#include<bits/stdc++.h>
#define inf (0x7f7f7f7f)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
typedef long long ll;
using namespace std;
template <class T>
inline void read(T &x){
    int f = 0, ch = 0; x = 0;
    for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = 1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    if(f) x = -x;
}
#define int ll

const int N = 200005, Mod = 1000000007;
int js[N], mu[N], b[N], prime[N], inv[N], tot, n, m;

inline int Pow(int a, int b){
    int ans = 1;
    for(; b; b >>= 1, a = a * a % Mod)
        if(b & 1) ans = ans * a % Mod;
    return ans;
}
inline void Prework(){
    mu[1] = 1, js[0] = 1, inv[0] = 1;
    for(int i = 1; i < N; i++)
        js[i] = js[i-1] * i % Mod, inv[i] = Pow(js[i], Mod - 2);
    for(int i = 2; i < N; i++){
        if(!b[i]) prime[++tot] = i, mu[i] = -1;
        for(int j = 1; j <= tot && i * prime[j] < N; j++){
            b[i*prime[j]] = 1;
            if(i % prime[j]) mu[i*prime[j]] = -mu[i]; else break;
        }
    }
}

inline int C(int n, int i){ return js[n] * inv[i] % Mod * inv[n-i] % Mod; }
inline int calc(int x){ return x < m ? 0 : C(x - 1, m - 1) * mu[n/x] % Mod; }

inline void solve(){
    int ans = 0; read(n), read(m);
    int num = (int) sqrt(n);
    for(int i = 1; i <= num; i++) if(n % i == 0){
        int x = i, y = n / i;
        (ans += calc(x)) %= Mod;
        if(x != y) (ans += calc(y)) %= Mod;
    }
    printf("%lld\n", ((ans % Mod) + Mod) % Mod);
}

signed main(){
    Prework();
    int T; read(T); while(T--) solve();
    return 0;
}


#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
using namespace std;

#define SET(p) memset(p, -1, sizeof(p))
#define CLR(p) memset(p, 0, sizeof(p))
#define MEM(p, v) memset(p, v, sizeof(p))
#define CPY(d, s) memcpy(d, s, sizeof(s))
#define ll long long
#define ld long double
#define mod 1000000007
#define inf 1LL<<60
#define pii pair< int, int >
#define pll pair< ll, ll >
#define psi pair< string, int >
#define N 100010
vector <int> d[N] ,p[N];
ll fact[N],ifact[N];
bool mark[N];
ll cnt[N];
ll mul_inv(ll a, ll b){
    ll b0 = b, t, q;
    ll x0 = 0, x1 = 1;
    if (b == 1) return 1;
    while (a > 1) {
        q = a / b;
        t = b, b = a % b, a = t;
        t = x0, x0 = x1 - q * x0, x1 = t;
    }
    if (x1 < 0) x1 += b0;
    return x1;
}
ll nCr(int n,int r){
	if(n<r)
		return 0;
	return (((fact[n]*ifact[r])%mod)*ifact[n-r])%mod;
}
void init(){
	for(int i=2;i<N;i++){
		for(int j=2*i;j<N;j+=i){
			d[j].push_back(i);
			mark[j] = true;
			if(!mark[i]){
				p[j].push_back(i);
			}
		}
	}
	fact[0] = 1;
	for(int i=1;i<N;i++)
		fact[i] = (fact[i-1]*i)%mod;
	ifact[N-1] = mul_inv(fact[N-1],mod);
	for(int i=N-2;i>=0;i--)
		ifact[i] = (ifact[i+1]*(i+1))%mod;
}
int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	init();
	int q;
	cin>>q;
	while(q--){
		int n,f;
		cin>>n>>f;
		if(f==1){
			cout<<(n==1)<<endl;
			continue;
		}
		ll ans = nCr(n-1,f-1);
		for(int i=d[n].size()-1;i>=0;i--){
			cnt[d[n][i]] = (cnt[d[n][i]]+nCr(n/d[n][i]-1,f-1))%mod;
			for(int j : p[d[n][i]]){
				cnt[j] = (cnt[j]-cnt[d[n][i]]+mod)%mod;
			}
			ans = (ans-cnt[d[n][i]]+mod)%mod;
		}
		cout<<ans<<endl;
		CLR(cnt);
	}
	return 0;
}


#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
using namespace std;

#define SET(p) memset(p, -1, sizeof(p))
#define CLR(p) memset(p, 0, sizeof(p))
#define MEM(p, v) memset(p, v, sizeof(p))
#define CPY(d, s) memcpy(d, s, sizeof(s))
#define ll long long
#define ld long double
#define mod 1000000007
#define inf 1LL<<60
#define pii pair< int, int >
#define pll pair< ll, ll >
#define psi pair< string, int >
#define N 100010
vector <int> d[N];
ll fact[N],ifact[N];
ll mul_inv(ll a, ll b){
    ll b0 = b, t, q;
    ll x0 = 0, x1 = 1;
    if (b == 1) return 1;
    while (a > 1) {
        q = a / b;
        t = b, b = a % b, a = t;
        t = x0, x0 = x1 - q * x0, x1 = t;
    }
    if (x1 < 0) x1 += b0;
    return x1;
}
ll nCr(int n,int r){
	if(n<r)
		return 0;
	return (((fact[n]*ifact[r])%mod)*ifact[n-r])%mod;
}
void init(){
	for(int i=1;i<N;i++){
		for(int j=2*i;j<N;j+=i){
			d[j].push_back(i);
		}
	}
	fact[0] = 1;
	for(int i=1;i<N;i++)
		fact[i] = (fact[i-1]*i)%mod;
	ifact[N-1] = mul_inv(fact[N-1],mod);
	for(int i=N-2;i>=0;i--)
		ifact[i] = (ifact[i+1]*(i+1))%mod;
}
int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	init();
	int q;
	cin>>q;
	while(q--){
		int n,f;
		cin>>n>>f;
		ll ans = nCr(n-1,f-1);
		for(int i=0;i<d[n].size();i++){
			ans = (ans-nCr(d[n][i]-1,f-1)+mod)%mod;
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
using namespace std;

#define SET(p) memset(p, -1, sizeof(p))
#define CLR(p) memset(p, 0, sizeof(p))
#define MEM(p, v) memset(p, v, sizeof(p))
#define CPY(d, s) memcpy(d, s, sizeof(s))
#define ll long long
#define ld long double
#define mod 1000000007
#define inf 1LL<<60
#define pii pair< int, int >
#define pll pair< ll, ll >
#define psi pair< string, int >
#define N 100010
vector <int> d[N];
ll fact[N],ifact[N];
ll mul_inv(ll a, ll b){
    ll b0 = b, t, q;
    ll x0 = 0, x1 = 1;
    if (b == 1) return 1;
    while (a > 1) {
        q = a / b;
        t = b, b = a % b, a = t;
        t = x0, x0 = x1 - q * x0, x1 = t;
    }
    if (x1 < 0) x1 += b0;
    return x1;
}
ll nCr(int n,int r){
	if(n<r)
		return 0;
	return (((fact[n]*ifact[r])%mod)*ifact[n-r])%mod;
}
void init(){
	for(int i=2;i<N;i++){
		for(int j=2*i;j<N;j+=i){
			d[j].push_back(i);
		}
	}
	fact[0] = 1;
	for(int i=1;i<N;i++)
		fact[i] = (fact[i-1]*i)%mod;
	ifact[N-1] = mul_inv(fact[N-1],mod);
	for(int i=N-2;i>=0;i--)
		ifact[i] = (ifact[i+1]*(i+1))%mod;
}
int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	init();
	int q;
	cin>>q;
	while(q--){
		int n,f;
		cin>>n>>f;
		ll ans = nCr(n-1,f-1);
		for(int i=0;i<d[n].size();i++){
			ans = (ans-nCr(d[n][i]-1,f-1)+mod)%mod;
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
using namespace std;

#define SET(p) memset(p, -1, sizeof(p))
#define CLR(p) memset(p, 0, sizeof(p))
#define MEM(p, v) memset(p, v, sizeof(p))
#define CPY(d, s) memcpy(d, s, sizeof(s))
#define ll long long
#define ld long double
#define mod 1000000007
#define inf 1LL<<60
#define pii pair< int, int >
#define pll pair< ll, ll >
#define psi pair< string, int >
#define N 100010
vector <int> d[N];
ll fact[N],ifact[N];
ll mul_inv(ll a, ll b){
    ll b0 = b, t, q;
    ll x0 = 0, x1 = 1;
    if (b == 1) return 1;
    while (a > 1) {
        q = a / b;
        t = b, b = a % b, a = t;
        t = x0, x0 = x1 - q * x0, x1 = t;
    }
    if (x1 < 0) x1 += b0;
    return x1;
}
ll nCr(int n,int r){
	if(n<r)
		return 0;
	return (((fact[n]*ifact[r])%mod)*ifact[n-r])%mod;
}
void init(){
	for(int i=1;i<N;i++){
		for(int j=2*i;j<N;j+=i){
			d[j].push_back(i);
		}
	}
	fact[0] = 1;
	for(int i=1;i<N;i++)
		fact[i] = (fact[i-1]*i)%mod;
	ifact[N-1] = mul_inv(fact[N-1],mod);
	for(int i=N-2;i>=0;i--)
		ifact[i] = (ifact[i+1]*(i+1))%mod;
}
int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	init();
	int q;
	cin>>q;
	while(q--){
		int n,f;
		cin>>n>>f;
		if(f==1){
			cout<<0<<endl;
			continue;
		}
		ll ans = nCr(n-1,f-1);
		for(int i=0;i<d[n].size();i++){
			ans = (ans-nCr(d[n][i]-1,f-1)+mod)%mod;
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
using namespace std;

#define SET(p) memset(p, -1, sizeof(p))
#define CLR(p) memset(p, 0, sizeof(p))
#define MEM(p, v) memset(p, v, sizeof(p))
#define CPY(d, s) memcpy(d, s, sizeof(s))
#define ll long long
#define ld long double
#define mod 1000000007
#define inf 1LL<<60
#define pii pair< int, int >
#define pll pair< ll, ll >
#define psi pair< string, int >
#define N 100010
vector <int> d[N] ,p[N];
ll fact[N],ifact[N];
bool mark[N];
ll cnt[N];
ll mul_inv(ll a, ll b){
    ll b0 = b, t, q;
    ll x0 = 0, x1 = 1;
    if (b == 1) return 1;
    while (a > 1) {
        q = a / b;
        t = b, b = a % b, a = t;
        t = x0, x0 = x1 - q * x0, x1 = t;
    }
    if (x1 < 0) x1 += b0;
    return x1;
}
ll nCr(int n,int r){
	if(n<r)
		return 0;
	return (((fact[n]*ifact[r])%mod)*ifact[n-r])%mod;
}
void init(){
	for(int i=2;i<N;i++){
		for(int j=2*i;j<N;j+=i){
			d[j].push_back(i);
			mark[j] = true;
			if(!mark[i]){
				p[j].push_back(i);
			}
		}
	}
	fact[0] = 1;
	for(int i=1;i<N;i++)
		fact[i] = (fact[i-1]*i)%mod;
	ifact[N-1] = mul_inv(fact[N-1],mod);
	for(int i=N-2;i>=0;i--)
		ifact[i] = (ifact[i+1]*(i+1))%mod;
}
int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	init();
	int q;
	cin>>q;
	while(q--){
		int n,f;
		cin>>n>>f;
		if(f==1){
			cout<<(n==1)<<endl;
			continue;
		}
		ll ans = nCr(n-1,f-1);
		for(int i=d[n].size()-1;i>=0;i--){
			cnt[d[n][i]] = (cnt[d[n][i]]+nCr(n/d[n][i]-1,f-1))%mod;
			for(int j : p[d[n][i]]){
				cnt[d[n][i]/j] = (cnt[d[n][i]/j]-cnt[d[n][i]]+mod)%mod;
			}
			ans = (ans-cnt[d[n][i]]+mod)%mod;
		}
		cout<<ans<<endl;
		CLR(cnt);
	}
	return 0;
}


#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
using namespace std;

#define SET(p) memset(p, -1, sizeof(p))
#define CLR(p) memset(p, 0, sizeof(p))
#define MEM(p, v) memset(p, v, sizeof(p))
#define CPY(d, s) memcpy(d, s, sizeof(s))
#define ll long long
#define ld long double
#define mod 1000000007
#define inf 1LL<<60
#define pii pair< int, int >
#define pll pair< ll, ll >
#define psi pair< string, int >
#define N 100010
vector <int> d[N] ,p[N];
ll fact[N],ifact[N];
bool mark[N];
ll cnt[N];
ll mul_inv(ll a, ll b){
    ll b0 = b, t, q;
    ll x0 = 0, x1 = 1;
    if (b == 1) return 1;
    while (a > 1) {
        q = a / b;
        t = b, b = a % b, a = t;
        t = x0, x0 = x1 - q * x0, x1 = t;
    }
    if (x1 < 0) x1 += b0;
    return x1;
}
ll nCr(int n,int r){
	if(n<r)
		return 0;
	return (((fact[n]*ifact[r])%mod)*ifact[n-r])%mod;
}
void init(){
	for(int i=2;i<N;i++){
		for(int j=2*i;j<N;j+=i){
			d[j].push_back(i);
			mark[j] = true;
			if(!mark[i]){
				p[j].push_back(i);
			}
		}
	}
	fact[0] = 1;
	for(int i=1;i<N;i++)
		fact[i] = (fact[i-1]*i)%mod;
	ifact[N-1] = mul_inv(fact[N-1],mod);
	for(int i=N-2;i>=0;i--)
		ifact[i] = (ifact[i+1]*(i+1))%mod;
}
int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	init();
	int q;
	cin>>q;
	while(q--){
		int n,f;
		cin>>n>>f;
		if(f==1){
			cout<<(n==1)<<endl;
			continue;
		}
		ll ans = nCr(n-1,f-1);
		for(int i=d[n].size()-1;i>=0;i--){
			cnt[d[n][i]] = (cnt[d[n][i]]+nCr(n/d[n][i]-1,f-1))%mod;
			for(int j : d[d[n][i]]){
				cnt[j] = (cnt[j]-cnt[d[n][i]]+mod)%mod;
			}
			ans = (ans-cnt[d[n][i]]+mod)%mod;
		}
		cout<<ans<<endl;
		CLR(cnt);
	}
	return 0;
}


#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
using namespace std;

#define SET(p) memset(p, -1, sizeof(p))
#define CLR(p) memset(p, 0, sizeof(p))
#define MEM(p, v) memset(p, v, sizeof(p))
#define CPY(d, s) memcpy(d, s, sizeof(s))
#define ll long long
#define ld long double
#define mod 1000000007
#define inf 1LL<<60
#define pii pair< int, int >
#define pll pair< ll, ll >
#define psi pair< string, int >
#define N 100010
vector <int> d[N];
ll fact[N],ifact[N];
ll dp[N];
int last[N];
int tm;
ll mul_inv(ll a, ll b){
    ll b0 = b, t, q;
    ll x0 = 0, x1 = 1;
    if (b == 1) return 1;
    while (a > 1) {
        q = a / b;
        t = b, b = a % b, a = t;
        t = x0, x0 = x1 - q * x0, x1 = t;
    }
    if (x1 < 0) x1 += b0;
    return x1;
}
ll nCr(int n,int r){
	if(n<r)
		return 0;
	return (((fact[n]*ifact[r])%mod)*ifact[n-r])%mod;
}
void init(){
	for(int i=2;i<N;i++){
		for(int j=2*i;j<N;j+=i){
			d[j].push_back(i);
		}
	}
	fact[0] = 1;
	for(int i=1;i<N;i++)
		fact[i] = (fact[i-1]*i)%mod;
	ifact[N-1] = mul_inv(fact[N-1],mod);
	for(int i=N-2;i>=0;i--)
		ifact[i] = (ifact[i+1]*(i+1))%mod;
}
ll solve(int n,int f){
	if(n<f)
		return 0;
	if(f==n)
		return 1;
	if(last[n]==tm)
		return dp[n];
	last[n] = tm;
	dp[n] = nCr(n-1,f-1);
	for(int i : d[n]){
		dp[n] = (dp[n]-solve(i,f)+mod)%mod;
	}
	return dp[n];
}
int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	init();
	int q;
	cin>>q;
	while(q--){
		int n,f;
		cin>>n>>f;
		if(f==1){
			cout<<(n==1)<<endl;
			continue;
		}
		tm++;
		cout<<solve(n,f)<<endl;
	}
	return 0;
}


#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
using namespace std;

#define SET(p) memset(p, -1, sizeof(p))
#define CLR(p) memset(p, 0, sizeof(p))
#define MEM(p, v) memset(p, v, sizeof(p))
#define CPY(d, s) memcpy(d, s, sizeof(s))
#define ll long long
#define ld long double
#define mod 1000000007
#define inf 1LL<<60
#define pii pair< int, int >
#define pll pair< ll, ll >
#define psi pair< string, int >
#define N 100010
vector <int> d[N];
ll fact[N],ifact[N];
ll mul_inv(ll a, ll b){
    ll b0 = b, t, q;
    ll x0 = 0, x1 = 1;
    if (b == 1) return 1;
    while (a > 1) {
        q = a / b;
        t = b, b = a % b, a = t;
        t = x0, x0 = x1 - q * x0, x1 = t;
    }
    if (x1 < 0) x1 += b0;
    return x1;
}
ll nCr(int n,int r){
	if(n<r)
		return 0;
	return (((fact[n]*ifact[r])%mod)*ifact[n-r])%mod;
}
void init(){
	for(int i=1;i<N;i++){
		for(int j=2*i;j<N;j+=i){
			d[j].push_back(i);
		}
	}
	fact[0] = 1;
	for(int i=1;i<N;i++)
		fact[i] = (fact[i-1]*i)%mod;
	ifact[N-1] = mul_inv(fact[N-1],mod);
	for(int i=N-2;i>=0;i--)
		ifact[i] = (ifact[i+1]*(i+1))%mod;
}
int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	init();
	int q;
	cin>>q;
	while(q--){
		int n,f;
		cin>>n>>f;
		if(f==1){
			cout<<(n==1)<<endl;
			continue;
		}
		ll ans = nCr(n-1,f-1);
		for(int i=0;i<d[n].size();i++){
			ans = (ans-nCr(d[n][i]-1,f-1)+mod)%mod;
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
using namespace std;

#define SET(p) memset(p, -1, sizeof(p))
#define CLR(p) memset(p, 0, sizeof(p))
#define MEM(p, v) memset(p, v, sizeof(p))
#define CPY(d, s) memcpy(d, s, sizeof(s))
#define ll long long
#define ld long double
#define mod 1000000007
#define inf 1LL<<60
#define pii pair< int, int >
#define pll pair< ll, ll >
#define psi pair< string, int >
#define N 100010
vector <int> d[N] ,p[N];
ll fact[N],ifact[N];
bool mark[N];
ll cnt[N];
ll mul_inv(ll a, ll b){
    ll b0 = b, t, q;
    ll x0 = 0, x1 = 1;
    if (b == 1) return 1;
    while (a > 1) {
        q = a / b;
        t = b, b = a % b, a = t;
        t = x0, x0 = x1 - q * x0, x1 = t;
    }
    if (x1 < 0) x1 += b0;
    return x1;
}
ll nCr(int n,int r){
	if(n<r)
		return 0;
	return (((fact[n]*ifact[r])%mod)*ifact[n-r])%mod;
}
void init(){
	mark[1] = true;
	for(int i=1;i<N;i++){
		for(int j=2*i;j<N;j+=i){
			d[j].push_back(i);
			mark[j] = true;
			if(!mark[i]){
				p[j].push_back(i);
			}
		}
	}
	fact[0] = 1;
	for(int i=1;i<N;i++)
		fact[i] = (fact[i-1]*i)%mod;
	ifact[N-1] = mul_inv(fact[N-1],mod);
	for(int i=N-2;i>=0;i--)
		ifact[i] = (ifact[i+1]*(i+1))%mod;
}
int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	init();
	int q;
	cin>>q;
	while(q--){
		int n,f;
		cin>>n>>f;
		if(f==1){
			cout<<(n==1)<<endl;
			continue;
		}
		ll ans = nCr(n-1,f-1);
		for(int i=d[n].size()-1;i>=0;i--){
			cnt[d[n][i]] = (cnt[d[n][i]]+nCr(n/d[n][i]-1,f-1))%mod;
			for(int j : p[d[n][i]]){
				cnt[j] = (cnt[j]-cnt[d[n][i]]+mod)%mod;
			}
			ans = (ans-cnt[d[n][i]]+mod)%mod;
		}
		cout<<ans<<endl;
		CLR(cnt);
	}
	return 0;
}


#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
using namespace std;

#define SET(p) memset(p, -1, sizeof(p))
#define CLR(p) memset(p, 0, sizeof(p))
#define MEM(p, v) memset(p, v, sizeof(p))
#define CPY(d, s) memcpy(d, s, sizeof(s))
#define ll long long
#define ld long double
#define mod 1000000007
#define inf 1LL<<60
#define pii pair< int, int >
#define pll pair< ll, ll >
#define psi pair< string, int >
#define N 100010
vector <int> d[N] ,p[N];
ll fact[N],ifact[N];
bool mark[N];
ll cnt[N];
ll mul_inv(ll a, ll b){
    ll b0 = b, t, q;
    ll x0 = 0, x1 = 1;
    if (b == 1) return 1;
    while (a > 1) {
        q = a / b;
        t = b, b = a % b, a = t;
        t = x0, x0 = x1 - q * x0, x1 = t;
    }
    if (x1 < 0) x1 += b0;
    return x1;
}
ll nCr(int n,int r){
	if(n<r)
		return 0;
	return (((fact[n]*ifact[r])%mod)*ifact[n-r])%mod;
}
void init(){
	for(int i=2;i<N;i++){
		for(int j=2*i;j<N;j+=i){
			d[j].push_back(i);
			mark[j] = true;
			if(!mark[i]){
				p[j].push_back(i);
			}
		}
	}
	fact[0] = 1;
	for(int i=1;i<N;i++)
		fact[i] = (fact[i-1]*i)%mod;
	ifact[N-1] = mul_inv(fact[N-1],mod);
	for(int i=N-2;i>=0;i--)
		ifact[i] = (ifact[i+1]*(i+1))%mod;
}
int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	init();
	int q;
	cin>>q;
	while(q--){
		int n,f;
		cin>>n>>f;
		if(f==1){
			cout<<(n==1)<<endl;
			continue;
		}
		ll ans = nCr(n-1,f-1);
		for(int i=d[n].size()-1;i>=0;i--){
			cnt[d[n][i]] = (cnt[d[n][i]]+nCr(n/d[n][i]-1,f-1))%mod;
			for(int j : p[d[n][i]]){
				cnt[j] = (cnt[j]-cnt[d[n][i]]+mod)%mod;
			}
			ans = (ans-cnt[d[n][i]]+mod)%mod;
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1e5 + 5;
const ll mod = 1e9 + 7;

ll fact[N], inv[N];
ll dp[N]; int done[N];
int q;
int id;
vector <ll> g[N];

ll bigmod(ll x, ll y) {
  ll res = 1;
  while(y) {
    if(y & 1) res = (res * x) % mod;
    y >>= 1;
    x = (x * x) % mod;
  }
  return res;
}

void pre() {
  fact[0] = 1, inv[0] = bigmod(1, mod - 2);
  for(int i = 1; i < N; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
    inv[i] = bigmod(fact[i], mod - 2);
    for(int j = i; j < N; j += i) {
      g[j].push_back(i);
    }
  }
}

ll ncr(ll n, ll r) {
  if(n < r or r < 0) return 0;
  ll up = (fact[n] * inv[r]) % mod;
  up = (up * inv[n - r]) % mod;
  return up;
}

ll go(ll n, ll f) {
  if(n < f) return 0;
  if(n == f) return 1;
  if(done[n] == id) return dp[n];
  done[n] = id;
  ll &ways = dp[n];
  ways = ncr(n - 1, f - 1);
  for(auto x : g[n]) if(x != n) {
    ways = (ways - go(x, f));
    if(ways < 0) ways += mod;
  }
  return ways;
}

int main() {
  pre();
  scanf("%d", &q);
  while(q--) {
    id++;
    ll n, f; scanf("%lld %lld", &n, &f);
    printf("%lld\n", go(n, f));
  }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1e5 + 5;
const ll mod = 1e9 + 7;

ll fact[N], inv[N];
ll dp[N]; int done[N];
int q;
int id;
vector <ll> p;
ll n, f;
//vector <ll> g[N];

ll bigmod(ll x, ll y) {
  ll res = 1;
  while(y) {
    if(y & 1) res = (res * x) % mod;
    y >>= 1;
    x = (x * x) % mod;
  }
  return res;
}

void pre() {
  fact[0] = 1, inv[0] = bigmod(1, mod - 2);
  for(int i = 1; i < N; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
    inv[i] = bigmod(fact[i], mod - 2);
    //for(int j = i; j < N; j += i) {
      //g[j].push_back(i);
    //}
  }
}

ll ncr(ll n, ll r) {
  if(n < r or r < 0) return 0;
  ll up = (fact[n] * inv[r]) % mod;
  up = (up * inv[n - r]) % mod;
  return up;
}

/*ll go(ll n, ll f) {
  if(n < f) return 0;
  if(n == f) return 1;
  if(done[n] == id) return dp[n];
  done[n] = id;
  ll &ways = dp[n];
  ways = ncr(n - 1, f - 1);
  for(auto x : g[n]) if(x != n) {
    ways = (ways - go(x, n));
    if(ways < 0) ways += mod;
  }
  return ways;
}*/

ll go(int idx, ll m, ll cnt) {
  ll cur = 0;
  if(idx == p.size()) {
    cur = ncr((n / m) - 1, f - 1);
    if(cnt & 1) cur = (-cur + mod) % mod;
  }
  else {
    cur = (cur + go(idx + 1, m, cnt)) % mod;
    cur = (cur + go(idx + 1, m * p[idx], cnt + 1)) % mod;
  }
  return cur;
}

int main() {
  pre();
  scanf("%d", &q);
  while(q--) {
    scanf("%lld %lld", &n, &f);
    ll cur = n;
    for(int i = 2; i * i <= cur; i++) {
      if(cur % i == 0) {
        p.push_back(i);
        while(cur % i == 0) cur /= i;
      }
    }
    if(cur > 1) p.push_back(cur);
    printf("%lld\n", go(0, 1ll, 0));
    p.clear();
  }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1e5 + 5;
const ll mod = 1e9 + 7;

ll fact[N], inv[N];
ll dp[N]; int done[N];
int q;
int id;
ll n, f;
vector <ll> prime;
vector <ll> g[N];
ll mobius[N];
bool composite[N];

void mobi() {
  memset(composite, false, sizeof composite);
  mobius[1] = 1;
  for(int i = 2; i < N; i++) {
    if(!composite[i]) {
      prime.push_back(i);
      mobius[i] = -1;
    }
    for(int j = 0; j < prime.size() and i * prime[j] < N; j++) {
      composite[i * prime[j]] = true;
      if(i % prime[j] == 0) {
        mobius[i * prime[j]] = 0;
        break;
      } else {
          mobius[i * prime[j]] = mobius[i] * mobius[prime[j]];
      }
    }
  }
}

ll bigmod(ll x, ll y) {
  ll res = 1;
  while(y) {
    if(y & 1) res = (res * x) % mod;
    y >>= 1;
    x = (x * x) % mod;
  }
  return res;
}

void pre() {
  fact[0] = 1, inv[0] = bigmod(1, mod - 2);
  for(int i = 1; i < N; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
    inv[i] = bigmod(fact[i], mod - 2);
    for(int j = i; j < N; j += i) {
      g[j].push_back(i);
    }
  }
}

ll ncr(ll n, ll r) {
  if(n < r or r < 0) return 0;
  ll up = (fact[n] * inv[r]) % mod;
  up = (up * inv[n - r]) % mod;
  return up;
}

/*ll go(ll n, ll f) {
  if(n < f) return 0;
  if(n == f) return 1;
  if(done[n] == id) return dp[n];
  done[n] = id;
  ll &ways = dp[n];
  ways = ncr(n - 1, f - 1);
  for(auto x : g[n]) if(x != n) {
    ways = (ways - go(x, n));
    if(ways < 0) ways += mod;
  }
  return ways;
}*/

/*ll go(int idx, ll m, ll cnt) {
  ll cur = 0;
  if(idx == p.size()) {
    cur = ncr((n / m) - 1, f - 1);
    if(cnt & 1) cur = (-cur + mod) % mod;
  }
  else {
    cur = (cur + go(idx + 1, m, cnt)) % mod;
    cur = (cur + go(idx + 1, m * p[idx], cnt + 1)) % mod;
  }
  return cur;
}*/

ll go(ll n, ll f) {
  ll res = 0;
  for(auto x : g[n]) {
    res = (res + mobius[n / x] * ncr(x - 1, f - 1));
  }
  return res;
}

int main() {
  mobi();
  pre();
  scanf("%d", &q);
  while(q--) {
    scanf("%lld %lld", &n, &f);
    printf("%lld\n", go(n, f));
  }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1e5 + 5;
const ll mod = 1e9 + 7;

ll fact[N], inv[N];
ll dp[N]; int done[N];
int id;
int q;
vector <ll> d[N];

ll bigmod(ll x, ll y) {
  ll res = 1ll;
  while(y) {
    if(y & 1) res = (res * x) % mod;
    y >>= 1ll;
    x = (x * x) % mod;
  }
  return res;
}

ll ncr(ll n, ll k) {
  if(k > n or k < 0) return 0;
  if(k == 0) return 1;
  ll up = fact[n];
  up = (up * inv[k]) % mod;
  up = (up * inv[n - k]) % mod;
  return up;
}

ll go(ll n, ll f) {
  if(n < f) return 0;
  if(n == f) return 1;
  //cout << n << ' ' << f << '\n';
  if(done[n] == id) return dp[n];
  done[n] = id;
  ll& ways = dp[n];
  ways = ncr(n - 1, f - 1);
  //cout << ways << '\n';
  for(auto x : d[n]) {
    //cout << go(x, f) << '\n';
    if(x == n) continue;
    ways = (ways - go(x, f));
    if(ways < 0) ways += mod;
  }
  return ways;
}

int main() {
  fact[0] = 1, inv[0] = bigmod(fact[0], mod - 2);
  for(int i = 1; i < N; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
    inv[i] = bigmod(fact[i], mod - 2);
    for(int j = i; j < N; j += i) {
      d[j].push_back(i);
    }
  }
  scanf("%d", &q);
  while(q--) {
    ll n, f; scanf("%lld %lld", &n, &f);
    id++;
    //go(n, f);
    printf("%lld\n", go(n, f));
  }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1e5 + 5;
const ll mod = 1e9 + 7;

ll fact[N], inv[N];
ll dp[N]; int done[N];
int q;
int id;
ll n, f;
vector <ll> prime;
vector <ll> g[N];
ll mobius[N];
bool composite[N];

void mobi() {
  memset(composite, false, sizeof composite);
  mobius[1] = 1;
  for(int i = 2; i < N; i++) {
    if(!composite[i]) {
      prime.push_back(i);
      mobius[i] = -1;
    }
    for(int j = 0; j < prime.size() and i * prime[j] < N; j++) {
      composite[i * prime[j]] = true;
      if(i % prime[j] == 0) {
        mobius[i * prime[j]] = 0;
        break;
      } else {
          mobius[i * prime[j]] = mobius[i] * mobius[prime[j]];
      }
    }
  }
}

ll bigmod(ll x, ll y) {
  ll res = 1;
  while(y) {
    if(y & 1) res = (res * x) % mod;
    y >>= 1;
    x = (x * x) % mod;
  }
  return res;
}

void pre() {
  fact[0] = 1, inv[0] = bigmod(1, mod - 2);
  for(int i = 1; i < N; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
    inv[i] = bigmod(fact[i], mod - 2);
    for(int j = i; j < N; j += i) {
      g[j].push_back(i);
    }
  }
}

ll ncr(ll n, ll r) {
  if(n < r or r < 0) return 0;
  ll up = (fact[n] * inv[r]) % mod;
  up = (up * inv[n - r]) % mod;
  return up;
}

/*ll go(ll n, ll f) {
  if(n < f) return 0;
  if(n == f) return 1;
  if(done[n] == id) return dp[n];
  done[n] = id;
  ll &ways = dp[n];
  ways = ncr(n - 1, f - 1);
  for(auto x : g[n]) if(x != n) {
    ways = (ways - go(x, n));
    if(ways < 0) ways += mod;
  }
  return ways;
}*/

/*ll go(int idx, ll m, ll cnt) {
  ll cur = 0;
  if(idx == p.size()) {
    cur = ncr((n / m) - 1, f - 1);
    if(cnt & 1) cur = (-cur + mod) % mod;
  }
  else {
    cur = (cur + go(idx + 1, m, cnt)) % mod;
    cur = (cur + go(idx + 1, m * p[idx], cnt + 1)) % mod;
  }
  return cur;
}*/

ll go(ll n, ll f) {
  ll res = 0;
  for(auto x : g[n]) {
    res = (res + mobius[n / x] * ncr(x - 1, f - 1)) % mod;
    if(res < 0) res += mod;
  }
  return res;
}

int main() {
  mobi();
  pre();
  scanf("%d", &q);
  while(q--) {
    scanf("%lld %lld", &n, &f);
    printf("%lld\n", go(n, f));
  }
}


#include <bits/stdc++.h>
using namespace std;
// n -> fila
// f-1 -> columna
typedef long long ll;
const ll mod = 1e9 + 7;
const int limN = 1e5 ;

ll euclid(ll a, ll b, ll &x, ll &y) {
	if (b) { ll d = euclid(b, a % b, y, x);
		return y -= a/b * x, d; }
	return x = 1, y = 0, a;
}

struct Mod {
	ll x;
    Mod() {}
	Mod(ll xx) : x(xx) {}
	Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
	Mod operator-(Mod b) { return Mod((x - b.x + mod) % mod); }
	Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
	Mod operator/(Mod b) { return *this * invert(b); }
	Mod invert(Mod a) {
		ll x, y, g = euclid(a.x, mod, x, y);
		assert(g == 1); return Mod((x + mod) % mod);
	}
	Mod operator^(ll e) {
		if (!e) return Mod(1);
		Mod r = *this ^ (e / 2); r = r * r;
		return e&1 ? *this * r : r;
	}
};

vector<int> divs[limN + 5];
Mod facs[limN + 5];
Mod finv[limN + 5];
int F ;
int usd[limN + 5];
int ans[limN + 5];
vector < pair<int, int> > qrs[limN + 5] ;
Mod dp[limN + 5];

Mod memo(int n) {
    if(n < F)
        return 0 ;
    if(usd[n] == F)
        return dp[n] ;
    usd[n] = F ;
    Mod &ans = dp[n];
    ans = facs[n-1] * finv[F-1] * finv[(n-1) - (F-1)] ;
    for(const int d : divs[n])
        ans = ans - memo(d) ;
    return ans;
}

void precarga() {
    int N = limN ;
    for(int i=2; i<=N; i++)
        for(int j=2*i; j<=N; j+=i)
            divs[j].push_back(i);
    facs[0] = finv[0] = 1;
    for(int i=1; i<=N; i++) {
        facs[i] = facs[i-1] * i;
        finv[i] = finv[i-1] / i;
    }
}

int main() {
    int Q ;
    precarga();

    scanf("%d", &Q);
    for(int i=0, a, b; i<Q; i++) {
        scanf("%d%d", &b, &a);
        qrs[a].push_back({b, i});
    }

    for(F = 1; F <= limN; F++) {
        for(const auto &p : qrs[F]) {
            int ap = p.second, n = p.first ;
            ans[ap] = memo(n).x ;
        }
    }

    for(int i=0; i<Q; i++)
        printf("%d\n", ans[i]);
}


#include <bits/stdc++.h>
using namespace std;
// n -> fila
// f-1 -> columna
typedef long long ll;
const ll mod = 1e9 + 7;
const int limN = 1e5 ;

ll euclid(ll a, ll b, ll &x, ll &y) {
	if (b) { ll d = euclid(b, a % b, y, x);
		return y -= a/b * x, d; }
	return x = 1, y = 0, a;
}

struct Mod {
	ll x;
    Mod() {}
	Mod(ll xx) : x(xx) {}
	Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
	Mod operator-(Mod b) { return Mod((x - b.x + mod) % mod); }
	Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
	Mod operator/(Mod b) { return *this * invert(b); }
	Mod invert(Mod a) {
		ll x, y, g = euclid(a.x, mod, x, y);
		assert(g == 1); return Mod((x + mod) % mod);
	}
	Mod operator^(ll e) {
		if (!e) return Mod(1);
		Mod r = *this ^ (e / 2); r = r * r;
		return e&1 ? *this * r : r;
	}
};

vector<int> divs[limN + 5];
Mod facs[limN + 5];
Mod finv[limN + 5];
int F ;
int usd[limN + 5];
int ans[limN + 5];
vector < pair<int, int> > qrs[limN + 5] ;
Mod dp[limN + 5];

Mod memo(int n) {
	if(F == 1 && n>1)
	return 0;
    if(n < F)
        return 0 ;
    if(usd[n] == F)
        return dp[n] ;
    usd[n] = F ;
    Mod &ans = dp[n];
    ans = facs[n-1] * finv[F-1] * finv[(n-1) - (F-1)] ;
    for(const int d : divs[n])
        ans = ans - memo(d) ;
    return ans;
}

void precarga() {
    int N = limN ;
    for(int i=2; i<=N; i++)
        for(int j=2*i; j<=N; j+=i)
            divs[j].push_back(i);
    facs[0] = finv[0] = 1;
    for(int i=1; i<=N; i++) {
        facs[i] = facs[i-1] * i;
        finv[i] = finv[i-1] / i;
    }
}

int main() {
    int Q ;
    precarga();

    scanf("%d", &Q);
    for(int i=0, a, b; i<Q; i++) {
        scanf("%d%d", &b, &a);
        qrs[a].push_back({b, i});
    }

    for(F = 1; F <= limN; F++) {
        for(const auto &p : qrs[F]) {
            int ap = p.second, n = p.first ;
            ans[ap] = memo(n).x ;
        }
    }

    for(int i=0; i<Q; i++)
        printf("%d\n", ans[i]);
}


#include<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007
#define dancila 3.14159265359
#define eps 1e-9

using namespace std;

typedef long long ll;

int add(int a, int b)
{
    ll x = a+b;
    if(x >= mod)
        x -= mod;
    if(x < 0)
        x += mod;
    return x;
}
ll mul(ll a, ll b)
{
    return (a*b) % mod;
}

ll pw(ll a, ll b)
{
    ll ans = 1;
    while(b)
    {
        if(b & 1)
            ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long rand_seed()
{
    long long a = rng();
    return a;
}
vector<int> divi[100002];
void ciur()
{
    for(int i = 2; i <= 100000; ++i)
    {
        if(divi[i].empty())
        {
            for(int j = i; j <= 100000; j += i)
                divi[j].pb(i);
        }
    }
}
ll fact[200002], inv[200002];
ll C(int n, int k)
{
    if(n < k)
        return 0;
    return mul(fact[n], mul(inv[k], inv[n-k]));
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    fact[0] = inv[0] = 1;
    for(int i = 1; i <= 200000; ++i)
    {
        fact[i] = mul(fact[i-1], i);
        inv[i] = pw(fact[i], mod - 2);
    }
    ciur();
    int q;
    cin >> q;
    for(; q; --q)
    {
        int n, t;
        cin >> n >> t;
        ll ans = 0;
        for(int i = 0; i < (1<<(divi[n].size())); ++i)
        {
            int odd = 0;
            int prod = 1;
            for(int j = 0; j < divi[n].size(); ++j)
                if(i & (1<<j))
                {
                    prod = prod * divi[n][j];
                    odd ^= 1;
                }
            if(odd == 0)
                ans = add(ans, C(n/prod - 1, t - 1));
            else
                ans = add(ans, -C(n/prod - 1, t - 1));
        }
        cout << ans << '\n';
    }
    return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define uid uniform_int_distribution
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const double PI = acos(-1);
template<class my>
using ind_set = tree<my,null_type,less<my>,rb_tree_tag,tree_order_statistics_node_update>;

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define loop(i,a,b) for(int i=a;i>=b;i--)
#define forr(x,arr) for(auto& x:arr)
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-7
#define sz(x) (int)(x).size()

using lli   = long long;
using lld   = long double;
using ulli  = unsigned long long int;
using pll   = pair<lli, lli>;
using ttt   = pair<lli, pll>;
using vttt  = vector<ttt>;
using vpll  = vector<pll>;
using vl    = vector<lli>;
using vvl   = vector<vector<lli>>;
using cd    = complex<long double>;

#ifdef tejasp
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.ff); __p(a.ss); cout << "} "; }
template<typename T, typename F, typename S>
void __p(pair<T,pair<F, S>> a) { cout << "{ "; __p(a.ff); __p(a.ss.ff); __p(a.ss.ss); cout << "} "; }
template<typename T>
void __p(std::vector<T> a) { cout << "{ "; for (auto p : a) __p(p); cout << "}"; }
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) { __p(a1); __p(a...); }
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout<<name<<" : ";__p(arg1);cout<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	int bracket=0,i=0;
	for(; ;i++)
		if(names[i]==','&&bracket==0)
			break;
		else if(names[i]=='(')
			bracket++;
		else if(names[i]==')')
			bracket--;
	const char *comma=names+i;
	cout.write(names,comma-names)<<" : ";
	__p(arg1);
	cout<<"| ";
	__f(comma+1,args...);
}
template<typename Arg1, typename Arg2>
void __f(const char *names, Arg1 arg1[], Arg2 &&arg2){
    int i=0;
	for(; ;i++) if(names[i]==',') break;
	cout.write(names,i)<<" : { ";
	fol(i,0,arg2) __p(arg1[i]);
	cout << "} "<<endl;
}
#define trace(...) { cout<<"Line:"<<__LINE__<<" | "; __f(#__VA_ARGS__, __VA_ARGS__); }
#else
#define endl '\n'
#define trace(...)
#endif

inline lli mpow(lli a, lli b, lli m=mod) {
    int ans = 1;
    a=((a%m)+m)%m;
    while (b) {
        if (b & 1) ans = (ans*a)%m;
        a = (a*a)%m;
        b >>= 1;
    }
    return ans;
}

vl prime;
vector<char> iscomp;
void sieve(int n)
{
    n+=10;
    iscomp.resize(n,0);
    fol(i,2,n)
    {
        if(!iscomp[i]) prime.pb(i);
        forr(x,prime)
        {
            if(x*i>=n) break;
            iscomp[x*i]=1;
        }
    }
}

lli fact[111111], invfact[111111];
vl pr[111111], prfac(111111);

lli nck (int n, int k)
{
    if(k<0||n<k) return 0;
    return (((fact[n]*invfact[k])%mod)*invfact[n-k])%mod;
}

lli calc(int n, int r)
{
    if(n<0||n<r) return 0;
    return nck(n-1,n-r);
}
void tejas_919(int kkkk)
{
    lli n, m, k, q, u, v, temp=0, ans;
    cin>>n>>m;
    if(m==1&&n>1) { cout<<0<<endl; return; }
    ans=calc(n,m);
    forr(x,pr[n])
    {
        if(prfac[x]>1)
        {
            temp=calc(n/x,m);
            trace(1,x,temp,prfac[x])
            temp=temp*(prfac[x]-1);
            ans=(ans+temp)%mod;
        }
        if(!iscomp[x])
        {
            temp=calc(n/x,m);
            trace(2,x,temp,prfac[x])
            ans=(ans+mod-temp)%mod;
        }
    }
    trace(ans)
    cout<<ans<<endl;
}

int main()
{
    #ifndef tejasp
        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #endif
    cout << fixed << setprecision(10);
    sieve(111111);
    forr(x,prime)
    {
        for(int j=x; j<111111; j+=x)
            prfac[j]++;
    }
    fol(i,2,111111)
    {
        for(int j=2*i; j<111111; j+=i)
            pr[j].pb(i);
    }
    fact[0]=1;
    fol(i,1,111111) fact[i]=(fact[i-1]*i)%mod;
    fol(i,0,111111) invfact[i]=mpow(fact[i],mod-2);
    int t=1;
    cin>>t;
    fol(i,0,t) { tejas_919(i+1); }
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define uid uniform_int_distribution
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const double PI = acos(-1);
template<class my>
using ind_set = tree<my,null_type,less<my>,rb_tree_tag,tree_order_statistics_node_update>;

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define loop(i,a,b) for(int i=a;i>=b;i--)
#define forr(x,arr) for(auto& x:arr)
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-7
#define sz(x) (int)(x).size()

using lli   = long long;
using lld   = long double;
using ulli  = unsigned long long int;
using pll   = pair<lli, lli>;
using ttt   = pair<lli, pll>;
using vttt  = vector<ttt>;
using vpll  = vector<pll>;
using vl    = vector<lli>;
using vvl   = vector<vector<lli>>;
using cd    = complex<long double>;

#ifdef tejasp
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.ff); __p(a.ss); cout << "} "; }
template<typename T, typename F, typename S>
void __p(pair<T,pair<F, S>> a) { cout << "{ "; __p(a.ff); __p(a.ss.ff); __p(a.ss.ss); cout << "} "; }
template<typename T>
void __p(std::vector<T> a) { cout << "{ "; for (auto p : a) __p(p); cout << "}"; }
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) { __p(a1); __p(a...); }
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout<<name<<" : ";__p(arg1);cout<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	int bracket=0,i=0;
	for(; ;i++)
		if(names[i]==','&&bracket==0)
			break;
		else if(names[i]=='(')
			bracket++;
		else if(names[i]==')')
			bracket--;
	const char *comma=names+i;
	cout.write(names,comma-names)<<" : ";
	__p(arg1);
	cout<<"| ";
	__f(comma+1,args...);
}
template<typename Arg1, typename Arg2>
void __f(const char *names, Arg1 arg1[], Arg2 &&arg2){
    int i=0;
	for(; ;i++) if(names[i]==',') break;
	cout.write(names,i)<<" : { ";
	fol(i,0,arg2) __p(arg1[i]);
	cout << "} "<<endl;
}
#define trace(...) { cout<<"Line:"<<__LINE__<<" | "; __f(#__VA_ARGS__, __VA_ARGS__); }
#else
#define endl '\n'
#define trace(...)
#endif

inline lli mpow(lli a, lli b, lli m=mod) {
    int ans = 1;
    a=((a%m)+m)%m;
    while (b) {
        if (b & 1) ans = (ans*a)%m;
        a = (a*a)%m;
        b >>= 1;
    }
    return ans;
}

vl prime;
vector<char> iscomp;
void sieve(int n)
{
    n+=10;
    iscomp.resize(n,0);
    fol(i,2,n)
    {
        if(!iscomp[i]) prime.pb(i);
        forr(x,prime)
        {
            if(x*i>=n) break;
            iscomp[x*i]=1;
        }
    }
}

lli fact[111111], invfact[111111];
vl pr[111111], prfac(111111);

lli nck (int n, int k)
{
    if(k<0||n<k) return 0;
    return (((fact[n]*invfact[k])%mod)*invfact[n-k])%mod;
}

lli calc(int n, int r)
{
    if(n<0||n<r) return 0;
    return nck(n-1,n-r);
}
void tejas_919(int kkkk)
{
    lli n, m, k, q, u, v, temp=0, ans;
    cin>>n>>m;
    if(m==1&&n>1) { cout<<0<<endl; return; }
    ans=calc(n,m);
    forr(x,pr[n])
    {
        trace(x,ans)
        if(prfac[x]>1)
        {
            temp=calc(n/x,m);
            trace(1,x,temp,prfac[x])
            temp=temp*(prfac[x]-1);
            ans=(ans+temp)%mod;
        }
        if(!iscomp[x])
        {
            temp=calc(n/x,m);
            trace(2,x,temp,prfac[x])
            ans=(ans+mod-temp)%mod;
        }
    }
    trace(ans)
    cout<<ans<<endl;
}

int main()
{
    #ifndef tejasp
        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #endif
    cout << fixed << setprecision(10);
    sieve(111111);
    fol(i,2,111111)
    {
        if(iscomp[i])
        {
            for(int j=2*i; j<111111; j+=i)
                prfac[j]--;
        }
        else
        {
            for(int j=2*i; j<111111; j+=i)
                prfac[j]++;
        }
    }
    fol(i,2,111111)
    {
        for(int j=2*i; j<111111; j+=i)
            pr[j].pb(i);
    }
    fact[0]=1;
    fol(i,1,111111) fact[i]=(fact[i-1]*i)%mod;
    fol(i,0,111111) invfact[i]=mpow(fact[i],mod-2);
    int t=1;
    cin>>t;
    fol(i,0,t) { tejas_919(i+1); }
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define uid uniform_int_distribution
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const double PI = acos(-1);
template<class my>
using ind_set = tree<my,null_type,less<my>,rb_tree_tag,tree_order_statistics_node_update>;

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define loop(i,a,b) for(int i=a;i>=b;i--)
#define forr(x,arr) for(auto& x:arr)
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-7
#define sz(x) (int)(x).size()

using lli   = long long;
using lld   = long double;
using ulli  = unsigned long long int;
using pll   = pair<lli, lli>;
using ttt   = pair<lli, pll>;
using vttt  = vector<ttt>;
using vpll  = vector<pll>;
using vl    = vector<lli>;
using vvl   = vector<vector<lli>>;
using cd    = complex<long double>;

#ifdef tejasp
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.ff); __p(a.ss); cout << "} "; }
template<typename T, typename F, typename S>
void __p(pair<T,pair<F, S>> a) { cout << "{ "; __p(a.ff); __p(a.ss.ff); __p(a.ss.ss); cout << "} "; }
template<typename T>
void __p(std::vector<T> a) { cout << "{ "; for (auto p : a) __p(p); cout << "}"; }
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) { __p(a1); __p(a...); }
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout<<name<<" : ";__p(arg1);cout<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	int bracket=0,i=0;
	for(; ;i++)
		if(names[i]==','&&bracket==0)
			break;
		else if(names[i]=='(')
			bracket++;
		else if(names[i]==')')
			bracket--;
	const char *comma=names+i;
	cout.write(names,comma-names)<<" : ";
	__p(arg1);
	cout<<"| ";
	__f(comma+1,args...);
}
template<typename Arg1, typename Arg2>
void __f(const char *names, Arg1 arg1[], Arg2 &&arg2){
    int i=0;
	for(; ;i++) if(names[i]==',') break;
	cout.write(names,i)<<" : { ";
	fol(i,0,arg2) __p(arg1[i]);
	cout << "} "<<endl;
}
#define trace(...) { cout<<"Line:"<<__LINE__<<" | "; __f(#__VA_ARGS__, __VA_ARGS__); }
#else
#define endl '\n'
#define trace(...)
#endif

inline lli mpow(lli a, lli b, lli m=mod) {
    int ans = 1;
    a=((a%m)+m)%m;
    while (b) {
        if (b & 1) ans = (ans*a)%m;
        a = (a*a)%m;
        b >>= 1;
    }
    return ans;
}

lli fact[111111], invfact[111111];
vl pr[111111];

lli calc (int n, int k)
{
    if(k<0||n<k) return 0;
    return (((fact[n]*invfact[k])%mod)*invfact[n-k])%mod;
}

void tejas_919(int kkkk)
{
    lli n, m, k, q, u, v, temp=0, ans=0;
    cin>>n>>m;
    fol(state,0,1<<sz(pr[n]))
    {
        lli val=1, sign=1;
        fol(i,0,sz(pr[n])) if(state&(1<<i)) { sign *= -1; val *= pr[n][i]; }
        trace(val,sign);
        ans=(ans+(sign*calc(n/val-1,m-1))+mod)%mod;
    }
    trace(ans)
    cout<<ans<<endl;
}

int main()
{
    #ifndef tejasp
        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #endif
    cout << fixed << setprecision(10);
    fol(x,2,111111)
    {
        if(sz(pr[x])) continue;
        for(int j=x; j<111111; j+=x)
            pr[j].pb(x);
    }
    fact[0]=1;
    fol(i,1,111111) fact[i]=(fact[i-1]*i)%mod;
    fol(i,0,111111) invfact[i]=mpow(fact[i],mod-2);
    int t=1;
    cin>>t;
    fol(i,0,t) { tejas_919(i+1); }
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define uid uniform_int_distribution
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const double PI = acos(-1);
template<class my>
using ind_set = tree<my,null_type,less<my>,rb_tree_tag,tree_order_statistics_node_update>;

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define loop(i,a,b) for(int i=a;i>=b;i--)
#define forr(x,arr) for(auto& x:arr)
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-7
#define sz(x) (int)(x).size()

using lli   = long long;
using lld   = long double;
using ulli  = unsigned long long int;
using pll   = pair<lli, lli>;
using ttt   = pair<lli, pll>;
using vttt  = vector<ttt>;
using vpll  = vector<pll>;
using vl    = vector<lli>;
using vvl   = vector<vector<lli>>;
using cd    = complex<long double>;

#ifdef tejasp
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.ff); __p(a.ss); cout << "} "; }
template<typename T, typename F, typename S>
void __p(pair<T,pair<F, S>> a) { cout << "{ "; __p(a.ff); __p(a.ss.ff); __p(a.ss.ss); cout << "} "; }
template<typename T>
void __p(std::vector<T> a) { cout << "{ "; for (auto p : a) __p(p); cout << "}"; }
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) { __p(a1); __p(a...); }
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout<<name<<" : ";__p(arg1);cout<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	int bracket=0,i=0;
	for(; ;i++)
		if(names[i]==','&&bracket==0)
			break;
		else if(names[i]=='(')
			bracket++;
		else if(names[i]==')')
			bracket--;
	const char *comma=names+i;
	cout.write(names,comma-names)<<" : ";
	__p(arg1);
	cout<<"| ";
	__f(comma+1,args...);
}
template<typename Arg1, typename Arg2>
void __f(const char *names, Arg1 arg1[], Arg2 &&arg2){
    int i=0;
	for(; ;i++) if(names[i]==',') break;
	cout.write(names,i)<<" : { ";
	fol(i,0,arg2) __p(arg1[i]);
	cout << "} "<<endl;
}
#define trace(...) { cout<<"Line:"<<__LINE__<<" | "; __f(#__VA_ARGS__, __VA_ARGS__); }
#else
#define endl '\n'
#define trace(...)
#endif

inline lli mpow(lli a, lli b, lli m=mod) {
    int ans = 1;
    a=((a%m)+m)%m;
    while (b) {
        if (b & 1) ans = (ans*a)%m;
        a = (a*a)%m;
        b >>= 1;
    }
    return ans;
}

vl prime;
vector<char> iscomp;
void sieve(int n)
{
    n+=10;
    iscomp.resize(n,0);
    fol(i,2,n)
    {
        if(!iscomp[i]) prime.pb(i);
        forr(x,prime)
        {
            if(x*i>=n) break;
            iscomp[x*i]=1;
        }
    }
}

lli fact[111111], invfact[111111];
vl pr[111111], prfac(111111);

lli nck (int n, int k)
{
    if(k<0||n<k) return 0;
    return (((fact[n]*invfact[k])%mod)*invfact[n-k])%mod;
}

lli calc(int n, int r)
{
    if(n<0||n<r) return 0;
    return nck(n-1,n-r);
}
void tejas_919(int kkkk)
{
    lli n, m, k, q, u, v, temp=0, ans;
    cin>>n>>m;
    if(m==1&&n>1) { cout<<0<<endl; return; }
    ans=calc(n,m);
    forr(x,pr[n])
    {
        trace(x,ans)
        if(prfac[x]>1)
        {
            temp=calc(n/x,m);
            trace(1,x,temp,prfac[x])
            temp=temp*(prfac[x]-1);
            ans=(ans+temp)%mod;
        }
        if(!iscomp[x])
        {
            temp=calc(n/x,m);
            trace(2,x,temp,prfac[x])
            ans=(ans+mod-temp)%mod;
        }
    }
    trace(ans)
    cout<<ans<<endl;
}

int main()
{
    #ifndef tejasp
        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #endif
    cout << fixed << setprecision(10);
    sieve(111111);
    fol(i,2,111111)
    {
        if(iscomp[i])
        {
            for(int j=2*i; j<111111; j+=i)
                prfac[j]-=prfac[i];
        }
        else
        {
            for(int j=2*i; j<111111; j+=i)
                prfac[j]++;
        }
    }
    fol(i,2,111111)
    {
        for(int j=2*i; j<111111; j+=i)
            pr[j].pb(i);
    }
    fact[0]=1;
    fol(i,1,111111) fact[i]=(fact[i-1]*i)%mod;
    fol(i,0,111111) invfact[i]=mpow(fact[i],mod-2);
    int t=1;
    cin>>t;
    fol(i,0,t) { tejas_919(i+1); }
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define uid uniform_int_distribution
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const double PI = acos(-1);
template<class my>
using ind_set = tree<my,null_type,less<my>,rb_tree_tag,tree_order_statistics_node_update>;

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define loop(i,a,b) for(int i=a;i>=b;i--)
#define forr(x,arr) for(auto& x:arr)
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-7
#define sz(x) (int)(x).size()

using lli   = long long;
using lld   = long double;
using ulli  = unsigned long long int;
using pll   = pair<lli, lli>;
using ttt   = pair<lli, pll>;
using vttt  = vector<ttt>;
using vpll  = vector<pll>;
using vl    = vector<lli>;
using vvl   = vector<vector<lli>>;
using cd    = complex<long double>;

#ifdef tejasp
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.ff); __p(a.ss); cout << "} "; }
template<typename T, typename F, typename S>
void __p(pair<T,pair<F, S>> a) { cout << "{ "; __p(a.ff); __p(a.ss.ff); __p(a.ss.ss); cout << "} "; }
template<typename T>
void __p(std::vector<T> a) { cout << "{ "; for (auto p : a) __p(p); cout << "}"; }
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) { __p(a1); __p(a...); }
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout<<name<<" : ";__p(arg1);cout<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	int bracket=0,i=0;
	for(; ;i++)
		if(names[i]==','&&bracket==0)
			break;
		else if(names[i]=='(')
			bracket++;
		else if(names[i]==')')
			bracket--;
	const char *comma=names+i;
	cout.write(names,comma-names)<<" : ";
	__p(arg1);
	cout<<"| ";
	__f(comma+1,args...);
}
template<typename Arg1, typename Arg2>
void __f(const char *names, Arg1 arg1[], Arg2 &&arg2){
    int i=0;
	for(; ;i++) if(names[i]==',') break;
	cout.write(names,i)<<" : { ";
	fol(i,0,arg2) __p(arg1[i]);
	cout << "} "<<endl;
}
#define trace(...) { cout<<"Line:"<<__LINE__<<" | "; __f(#__VA_ARGS__, __VA_ARGS__); }
#else
#define endl '\n'
#define trace(...)
#endif

inline lli mpow(lli a, lli b, lli m=mod) {
    int ans = 1;
    a=((a%m)+m)%m;
    while (b) {
        if (b & 1) ans = (ans*a)%m;
        a = (a*a)%m;
        b >>= 1;
    }
    return ans;
}

lli fact[111111], invfact[111111];
vl pr[111111];

lli nck (int n, int k)
{
    if(k<0||n<k) return 0;
    return (((fact[n]*invfact[k])%mod)*invfact[n-k])%mod;
}

lli calc(int n, int r)
{
    if(n<0||n<r) return 0;
    return nck(n-1,n-r);
}
void tejas_919(int kkkk)
{
    lli n, m, k, q, u, v, temp=0, ans;
    cin>>n>>m;
    ans=calc(n,m);
    forr(x,pr[n])
    {
        temp=calc(x,m);
        ans=(ans+mod-temp)%mod;
    }
    trace(ans)
    cout<<ans<<endl;
}

int main()
{
    #ifndef tejasp
        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #endif
    cout << fixed << setprecision(10);
    fol(i,1,111111)
    {
        for(int j=2*i; j<111111; j+=i)
            pr[j].pb(i);
    }
    fact[0]=1;
    fol(i,1,111111) fact[i]=(fact[i-1]*i)%mod;
    fol(i,0,111111) invfact[i]=mpow(fact[i],mod-2);
    int t=1;
    cin>>t;
    fol(i,0,t) { tejas_919(i+1); }
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define uid uniform_int_distribution
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const double PI = acos(-1);
template<class my>
using ind_set = tree<my,null_type,less<my>,rb_tree_tag,tree_order_statistics_node_update>;

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define loop(i,a,b) for(int i=a;i>=b;i--)
#define forr(x,arr) for(auto& x:arr)
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-7
#define sz(x) (int)(x).size()

using lli   = long long;
using lld   = long double;
using ulli  = unsigned long long int;
using pll   = pair<lli, lli>;
using ttt   = pair<lli, pll>;
using vttt  = vector<ttt>;
using vpll  = vector<pll>;
using vl    = vector<lli>;
using vvl   = vector<vector<lli>>;
using cd    = complex<long double>;

#ifdef tejasp
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.ff); __p(a.ss); cout << "} "; }
template<typename T, typename F, typename S>
void __p(pair<T,pair<F, S>> a) { cout << "{ "; __p(a.ff); __p(a.ss.ff); __p(a.ss.ss); cout << "} "; }
template<typename T>
void __p(std::vector<T> a) { cout << "{ "; for (auto p : a) __p(p); cout << "}"; }
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) { __p(a1); __p(a...); }
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout<<name<<" : ";__p(arg1);cout<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	int bracket=0,i=0;
	for(; ;i++)
		if(names[i]==','&&bracket==0)
			break;
		else if(names[i]=='(')
			bracket++;
		else if(names[i]==')')
			bracket--;
	const char *comma=names+i;
	cout.write(names,comma-names)<<" : ";
	__p(arg1);
	cout<<"| ";
	__f(comma+1,args...);
}
template<typename Arg1, typename Arg2>
void __f(const char *names, Arg1 arg1[], Arg2 &&arg2){
    int i=0;
	for(; ;i++) if(names[i]==',') break;
	cout.write(names,i)<<" : { ";
	fol(i,0,arg2) __p(arg1[i]);
	cout << "} "<<endl;
}
#define trace(...) { cout<<"Line:"<<__LINE__<<" | "; __f(#__VA_ARGS__, __VA_ARGS__); }
#else
#define endl '\n'
#define trace(...)
#endif

inline lli mpow(lli a, lli b, lli m=mod) {
    int ans = 1;
    a=((a%m)+m)%m;
    while (b) {
        if (b & 1) ans = (ans*a)%m;
        a = (a*a)%m;
        b >>= 1;
    }
    return ans;
}

vl prime;
vector<char> iscomp;
void sieve(int n)
{
    n+=10;
    iscomp.resize(n,0);
    fol(i,2,n)
    {
        if(!iscomp[i]) prime.pb(i);
        forr(x,prime)
        {
            if(x*i>=n) break;
            iscomp[x*i]=1;
        }
    }
}

lli fact[111111], invfact[111111];
vl pr[111111], prfac(111111);

lli calc (int n, int k)
{
    if(k<0||n<k) return 0;
    return (((fact[n]*invfact[k])%mod)*invfact[n-k])%mod;
}

void tejas_919(int kkkk)
{
    lli n, m, k, q, u, v, temp=0, ans=0;
    cin>>n>>m;
    fol(state,0,1<<sz(pr[n]))
    {
        lli val=1, sign=1;
        fol(i,0,sz(pr[n])) if(state&(1<<i)) { sign *= -1; val *= pr[n][i]; }
        ans=(ans+(sign*calc(n/val-1,m-1))+mod)%mod;
    }
    trace(ans)
    cout<<ans<<endl;
}

int main()
{
    #ifndef tejasp
        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #endif
    cout << fixed << setprecision(10);
    sieve(111111);
    forr(x,prime)
    {
        for(int j=x; j<111111; j+=x)
            pr[j].pb(x);
    }
    fact[0]=1;
    fol(i,1,111111) fact[i]=(fact[i-1]*i)%mod;
    fol(i,0,111111) invfact[i]=mpow(fact[i],mod-2);
    int t=1;
    cin>>t;
    fol(i,0,t) { tejas_919(i+1); }
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define uid uniform_int_distribution
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const double PI = acos(-1);
template<class my>
using ind_set = tree<my,null_type,less<my>,rb_tree_tag,tree_order_statistics_node_update>;

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define loop(i,a,b) for(int i=a;i>=b;i--)
#define forr(x,arr) for(auto& x:arr)
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-7
#define sz(x) (int)(x).size()

using lli   = long long;
using lld   = long double;
using ulli  = unsigned long long int;
using pll   = pair<lli, lli>;
using ttt   = pair<lli, pll>;
using vttt  = vector<ttt>;
using vpll  = vector<pll>;
using vl    = vector<lli>;
using vvl   = vector<vector<lli>>;
using cd    = complex<long double>;

#ifdef tejasp
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.ff); __p(a.ss); cout << "} "; }
template<typename T, typename F, typename S>
void __p(pair<T,pair<F, S>> a) { cout << "{ "; __p(a.ff); __p(a.ss.ff); __p(a.ss.ss); cout << "} "; }
template<typename T>
void __p(std::vector<T> a) { cout << "{ "; for (auto p : a) __p(p); cout << "}"; }
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) { __p(a1); __p(a...); }
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout<<name<<" : ";__p(arg1);cout<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	int bracket=0,i=0;
	for(; ;i++)
		if(names[i]==','&&bracket==0)
			break;
		else if(names[i]=='(')
			bracket++;
		else if(names[i]==')')
			bracket--;
	const char *comma=names+i;
	cout.write(names,comma-names)<<" : ";
	__p(arg1);
	cout<<"| ";
	__f(comma+1,args...);
}
template<typename Arg1, typename Arg2>
void __f(const char *names, Arg1 arg1[], Arg2 &&arg2){
    int i=0;
	for(; ;i++) if(names[i]==',') break;
	cout.write(names,i)<<" : { ";
	fol(i,0,arg2) __p(arg1[i]);
	cout << "} "<<endl;
}
#define trace(...) { cout<<"Line:"<<__LINE__<<" | "; __f(#__VA_ARGS__, __VA_ARGS__); }
#else
#define endl '\n'
#define trace(...)
#endif

inline lli mpow(lli a, lli b, lli m=mod) {
    int ans = 1;
    a=((a%m)+m)%m;
    while (b) {
        if (b & 1) ans = (ans*a)%m;
        a = (a*a)%m;
        b >>= 1;
    }
    return ans;
}

vl prime;
vector<char> iscomp;
void sieve(int n)
{
    n+=10;
    iscomp.resize(n,0);
    fol(i,2,n)
    {
        if(!iscomp[i]) prime.pb(i);
        forr(x,prime)
        {
            if(x*i>=n) break;
            iscomp[x*i]=1;
        }
    }
}

lli fact[111111], invfact[111111];
vl pr[111111], prfac(111111);

lli nck (int n, int k)
{
    if(k<0||n<k) return 0;
    return (((fact[n]*invfact[k])%mod)*invfact[n-k])%mod;
}

lli calc(int n, int r)
{
    if(n<0||n<r) return 0;
    return nck(n-1,n-r);
}
void tejas_919(int kkkk)
{
    lli n, m, k, q, u, v, temp=0, ans;
    cin>>n>>m;
    if(m==1&&n>1) { cout<<0<<endl; return; }
    ans=calc(n,m);
    forr(x,pr[n])
    {
        if(prfac[x]>1)
        {
            temp=calc(n/x,m);
            temp=temp*(prfac[x]-1);
            ans=(ans+temp)%mod;
        }
        else
        {
            temp=calc(n/x,m);
            ans=(ans+mod-temp)%mod;
        }
    }
    trace(ans)
    cout<<ans<<endl;
}

int main()
{
    #ifndef tejasp
        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #endif
    cout << fixed << setprecision(10);
    sieve(111111);
    forr(x,prime)
    {
        for(int j=x; j<111111; j+=x)
            prfac[j]++;
    }
    fol(i,2,111111)
    {
        for(int j=2*i; j<111111; j+=i)
            pr[j].pb(i);
    }
    fact[0]=1;
    fol(i,1,111111) fact[i]=(fact[i-1]*i)%mod;
    fol(i,0,111111) invfact[i]=mpow(fact[i],mod-2);
    int t=1;
    cin>>t;
    fol(i,0,t) { tejas_919(i+1); }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll MOD=1e9+7;
const ll maxn=1e5;
vector<ll> fact,fact_inv;
vector<vector<ll>> dv;	// ds[i]: contains the list of divisors of i
ll query=1;
vector<ll> dp,used;
ll power(ll a,ll b)
{
	ll res=1;
	a%=MOD;
	while(b>0)
	{
		if(b%2) res=(res*a)%MOD;
		a=(a*a)%MOD;
		b/=2;
	}
	return res;
}
ll modInv(ll x)
{
	return power(x,MOD-2);
}
void precompute()
{
	fact.resize(maxn+1);
	fact_inv.resize(maxn+1);
	fact[0]=fact_inv[0]=1;
	for(ll i=1;i<=maxn;i++)
	{
		fact[i]=(fact[i-1]*i)%MOD;
		fact_inv[i]=modInv(fact[i]);
	}

	dv.resize(maxn+1,vector<ll>());
	for(ll i=1;i<=maxn;i++)
	{
		for(ll j=2;j*j<=i;j++)
		{
			if(i%j==0)
			{
				dv[i].push_back(j);
				if(i/j!=j) dv[i].push_back(i/j);
			}
		}
		dv[i].push_back(i);
		sort(dv[i].begin(),dv[i].end());
	}
	dp.resize(maxn+1,0);
	used.resize(maxn+1,0);
}
ll ncr(ll n,ll r)
{
	ll ret=fact[n];
	ret=(ret*fact_inv[n-r])%MOD;
	ret=(ret*fact_inv[r])%MOD;
	return ret;
}
ll calc(ll n,ll f)
{
	if(n==f) return 1;
	if(f>n) return 0;

	if(used[n]==query) return dp[n];

	used[n]=query;
	ll ans=ncr(n-1,f-1);
	for(ll i=0;i<dv[n].size();i++)
	{
		ans=ans-calc(n/dv[n][i],f);
		if(ans<0) ans+=MOD;
	}
	return dp[n]=ans;
}
void solve()
{
	ll n,f;
	cin>>n>>f;
	cout<<calc(n,f)<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll T=1;
	cin>>T;
	precompute();
	while(T--)
	{
		solve();
		query++;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll MOD=1e9+7;
const ll maxn=1e5;
vector<ll> fact,fact_inv;
vector<vector<ll>> dv;	// ds[i]: contains the list of divisors of i
ll query=1;
vector<ll> dp,used;
ll power(ll a,ll b)
{
	ll res=1;
	a%=MOD;
	while(b>0)
	{
		if(b%2) res=(res*a)%MOD;
		a=(a*a)%MOD;
		b/=2;
	}
	return res;
}
ll modInv(ll x)
{
	return power(x,MOD-2);
}
void precompute()
{
	fact.resize(maxn+1);
	fact_inv.resize(maxn+1);
	fact[0]=fact_inv[0]=1;
	for(ll i=1;i<=maxn;i++)
	{
		fact[i]=(fact[i-1]*i)%MOD;
		fact_inv[i]=modInv(fact[i]);
	}

	dv.resize(maxn+1,vector<ll>());
	for(ll i=2;i<=maxn;i++)
	{
		for(ll j=2;j*j<=i;j++)
		{
			if(i%j==0)
			{
				dv[i].push_back(j);
				if(i/j!=j) dv[i].push_back(i/j);
			}
		}
		sort(dv[i].begin(),dv[i].end());
	}
	dp.resize(maxn+1,0);
	used.resize(maxn+1,0);
}
ll ncr(ll n,ll r)
{
	ll ret=fact[n];
	ret=(ret*fact_inv[n-r])%MOD;
	ret=(ret*fact_inv[r])%MOD;
	return ret;
}
ll calc(ll n,ll f)
{
	if(n==f) return 1;
	if(f>n) return 0;

	if(used[n]==query) return dp[n];

	used[n]=query;
	ll ans=ncr(n-1,f-1);
	for(ll i=0;i<dv[n].size();i++)
	{
		ans=ans-calc(n/dv[n][i],f);
		if(ans<0) ans+=MOD;
	}
	return dp[n]=ans;
}
void solve()
{
	ll n,f;
	cin>>n>>f;
	cout<<calc(n,f)<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll T=1;
	cin>>T;
	precompute();
	while(T--)
	{
		solve();
		query++;
	}
	return 0;
}