#include<vector>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<stdio.h>
#include<utility>

#include<iomanip>
#include <cstdlib>
#define ll long long
#define ef else if
#define rep(i,s,n) for(ll i=s;i<n;i=i+1)
#define rev(i,s,n) for(int i=s;i>n;i=i-1)
using namespace std;
#define fr first
#define se second
#define pb push_back
#define mp make_pair
#define mv vector<int>
#define vv vector< vector<int> >
#define vii vector< pair <int,int> >
#include <queue>
#define  id(h) isdigit(h)
//#define d double
#define all(a)  a.begin(),a.end()

mv chk(mv f)
{
    rep(i,0,4){
        int j=0;
        while(j<16 &&  f[i+j] !=0)j+=4;
        if(j==16){
            j=0;
            while(j<16){
                f[i+j]=0;
                j+=4;
            }
        }
    }
    for(int i=0 ;i<16 ;i+=4)
    {
        int j=i;
        for(;j<4+i && f[j]!=0 ;j++ );

            if(j==4+i){
                j=i;//cout<<"here"<<endl;
                for( ; j<4+i ; j++ )f[j]=0;
            }
    }
    return f;
}
int main()
{
    string s;//rep(i,0,1000)s+='0';

    cin>>s;
    mv f;rep(i,0,16)f.pb(0);
    int p;
    rep(i,0,s.size())
    {
        f = chk(f);
        /*rep(j,0,16)cout<<f[j]<<" ";
        cout<<endl;*/
        if( s[i]== '0'){
            p=0;
            while( p<12 && !(f[p]==0 &&f[p+4]==0) )p++;
            f[p]=1;f[p+4]=1;
            cout<<p/4 +1 <<" "<<p%4 +1<<endl;
            //cout<<p<<endl;
        }
        else{
            p=0;
            while((p+1)%4==0 || !(f[p]==0 && f[p+1]==0))p++;
            f[p]=1;f[p+1]=1;
            cout<<p/4 +1 <<" "<<p%4 +1<<endl;
            //cout<<p<<endl;
        }

    }f = chk(f);
    /*rep(j,0,16)cout<<f[j]<<" ";
        cout<<endl;*/
}


#include<vector>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<stdio.h>
#include<utility>

#include<iomanip>
#include <cstdlib>
#define ll long long
#define ef else if
#define rep(i,s,n) for(ll i=s;i<n;i=i+1)
#define rev(i,s,n) for(int i=s;i>n;i=i-1)
using namespace std;
#define fr first
#define se second
#define pb push_back
#define mp make_pair
#define mv vector<int>
#define vv vector< vector<int> >
#define vii vector< pair <int,int> >
#include <queue>
#define  id(h) isdigit(h)
//#define d double
#define all(a)  a.begin(),a.end()

mv chk(mv f)
{
    rep(i,0,4){
        int j=0;
        while(j<16 &&  f[i+j] !=0)j+=4;
        if(j==16){
            j=0;
            while(j<16){
                f[i+j]=0;
                j+=4;
            }
        }
    }
    for(int i=0 ;i<16 ;i+=4)
    {
        int j=i;
        for(;j<4+i && f[j]!=0 ;j++ );

            if(j==4+i){
                j=i;//cout<<"here"<<endl;
                for( ; j<4+i ; j++ )f[j]=0;
            }
    }
    return f;
}
int main()
{
    string s;//rep(i,0,1000)s+='0';

    cin>>s;
    mv f;rep(i,0,16)f.pb(0);
    int p;
    rep(i,0,s.size())
    {
        f = chk(f);
        /*rep(j,0,16)cout<<f[j]<<" ";
        cout<<endl;*/
        if( s[i]== '0'){
            p=0;
            while(!(f[p]==0 &&f[p+4]==0) )p++;
            f[p]=1;f[p+4]=1;
            cout<<p/4 +1 <<" "<<p%4 +1<<endl;
            //cout<<p<<endl;
        }
        else{
            p=0;
            while((p+1)%4==0 || !(f[p]==0 && f[p+1]==0))p++;
            f[p]=1;f[p+1]=1;
            cout<<p/4 +1 <<" "<<p%4 +1<<endl;
            //cout<<p<<endl;
        }

    }f = chk(f);
    /*rep(j,0,16)cout<<f[j]<<" ";
        cout<<endl;*/
}


#include<vector>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<stdio.h>
#include<utility>

#include<iomanip>
#include <cstdlib>
#define ll long long
#define ef else if
#define rep(i,s,n) for(ll i=s;i<n;i=i+1)
#define rev(i,s,n) for(int i=s;i>n;i=i-1)
using namespace std;
#define fr first
#define se second
#define pb push_back
#define mp make_pair
#define mv vector<int>
#define vv vector< vector<int> >
#define vii vector< pair <int,int> >
#include <queue>
#define  id(h) isdigit(h)
//#define d double
#define all(a)  a.begin(),a.end()

int main()
{
    string s;
    cin>>s;
    int x=1;
    int y=1;
    for(int i=0; i<s.size(); i++){
        if(s[i]=='1'){
            cout<<1<<' '<<x<<endl;
            x+=2;
            x%=4;
        }else {
            cout<<3<<' '<<y<<endl;
            y+=1;
            if(y==5) y=1;
        }
    }

}


#include<bits/stdc++.h>
using namespace std ;

int main()
{
    string s ;
    cin>>s ;
    int o = 1 , ov = 1 ;
    for(int i = 0 ; i < s.length() ; i++)
    {
        if(s[i]=='1')
        {
            if(o) cout<<1<<' '<<1<<endl;
            else cout<<1<<' '<<2<<endl;
            o = 0 ;
        }
        else
        {
            if(ov) cout<<1<<' '<<4<<endl;
            else cout<<3<<' '<<4<<endl;
            ov = 0 ;
        }
    }
}


#include<bits/stdc++.h>
using namespace std ;

int main()
{
    string s ;
    cin>>s ;
    int o = 1 , ov = 1 ;
    for(int i = 0 ; i < s.length() ; i++)
    {
        if(s[i]=='1')
        {
            if(o) cout<<4<<' '<<3<<endl;
            else cout<<4<<' '<<1<<endl;
            o = 0 ;
        }
        else
        {
            if(ov) cout<<1<<' '<<4<<endl;
            else cout<<3<<' '<<4<<endl;
            ov = 0 ;
        }
    }
}


#include<bits/stdc++.h>
using namespace std ;

int main()
{
    string s ;
    cin>>s ;
    int o = 0 , ov = 0 ;
    for(int i = 0 ; i < s.length() ; i++)
    {
        if(s[i]=='0')
        {
            if(ov) cout<<3<<' '<<4<<endl , ov = 0 ;
            else cout<<1<<' '<<4<<endl , ov = 1 ;
        }
        else
        {
            if(o) cout<<4<<' '<<3<<endl , o = 0 ;
            else cout<<4<<' '<<1<<endl , o = 1 ;
        }
    }
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cstring>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <unordered_map>
#include <list>
#include <time.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef pair<int, ll> Pil;
typedef pair<double, int> Pdi;
typedef tuple<int, int, int> Ti;
typedef tuple<int, int, ll> Tiil;
typedef tuple<ll, int, int> Tlii;
typedef tuple<ll, ll, int> Tlli;

#define Fi first
#define Se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define rep(pos, len) for(int pos=0;pos<len;pos++)
#define repp(pos, len) for(int pos=1;pos<=len;pos++)
#define all(x) x.begin(), x.end()

#define ABS(x) (((x) > 0 ) ? (x) : (-(x)))
#define MAX2(x, y) (((x) > (y)) ? (x) : (y))
#define MIN2(x, y) (((x) < (y)) ? (x) : (y))
#define MAX3(x, y, z) ( (x) > (y)  ? ( (x) > (z) ? (x) : (z)  ) : ( (y) > (z) ? (y) : (z) )  )
#define MIN3(x, y, z) ( (x) < (y)  ? ( (x) < (z) ? (x) : (z)  ) : ( (y) < (z) ? (y) : (z) )  )
#define MID3(val1,val2,val3) MAX2(MIN2(MAX2(val1,val2),val3),MIN2(val1,val2))

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME

#define geti1(X) scanf("%d",&X)
#define geti2(X,Y) scanf("%d%d",&X,&Y)
#define geti3(X,Y,Z) scanf("%d%d%d",&X,&Y,&Z)
#define geti4(X,Y,Z,W) scanf("%d%d%d%d",&X,&Y,&Z,&W)
#define geti(...) GET_MACRO(__VA_ARGS__, geti4, geti3, geti2, geti1) (__VA_ARGS__)

#define getll1(X) scanf("%lld",&X)
#define getll2(X,Y) scanf("%lld%lld",&X,&Y)
#define getll3(X,Y,Z) scanf("%lld%lld%lld",&X,&Y,&Z)
#define getll4(X,Y,Z,W) scanf("%lld%lld%lld%lld",&X,&Y,&Z,&W)
#define getll(...) GET_MACRO(__VA_ARGS__, getll4, getll3, getll2, getll1) (__VA_ARGS__)

#define dout(n) printf("%d\n",n)
#define lldout(n) printf("%lld\n",n)

// 1-index
#define L(x) ((x)<<1)
#define R(x) (((x)<<1)+1)

#define INF 987654321
#define IINF 98765432198765432
#define MOD 1000000007

const int MAXN = 1e5 + 50;

ll fact[MAXN], finv[MAXN];	// fact[n] = n!, finv[MAXN] = (n!)^(-1)
bool vis[MAXN];
vector<int> pfactor[MAXN];

ll inverse(ll a, ll m) {
    ll m0 = m, t, q;
    ll x0 = 0, x1 = 1;

    if (m == 1)
      return 0;

    while (a > 1) {
        // q is quotient
        q = a / m;
        t = m;

        // m is remainder now, process same as
        // Euclid's algo
        m = a % m, a = t;
        t = x0;
        x0 = x1 - q * x0;
        x1 = t;
    }

    // Make x1 positive
    if (x1 < 0)
       x1 += m0;
    return x1;
}

ll c(int n, int k) {
	return (((fact[n] * finv[k]) % MOD) * finv[n-k]) % MOD;
}

void findPrime() {
	for(int n = 2; n <= 1e5; n++) {
		if(vis[n]) continue;
		vis[n] = true;
		for(int k = 1; k * n <= 1e5; k++) {
			vis[k * n] = true;
			pfactor[k * n].pb(n);
		}
	}
}

void init() {
	fact[0] = 1;
	repp(n, 1e5) fact[n] = (fact[n-1] * n) % MOD;
	finv[0] = 1;
	repp(n, 1e5) finv[n] = inverse(fact[n], MOD);
}

int main() {
	init();
	findPrime();

	int T;
	geti(T);
	while(T--) {
		int n, f;
		geti(n, f);
		ll ans = 0;
		for(int mask = 0; mask < (1 << pfactor[n].size()); mask++) {
			int cnt = 0;
			int tmp = n;
			rep(i, pfactor[n].size()) {
				if((mask >> i) & 1) {
					tmp /= pfactor[n][i];
					cnt++;
				}
			}
			if(cnt & 1) {
				ans = (ans - c(tmp - 1, f - 1) + MOD) % MOD;
			} else {
				ans = (ans + c(tmp - 1, f - 1)) % MOD;
			}
		}

		printf("%d\n", (int)ans);
	}
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cstring>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <unordered_map>
#include <list>
#include <time.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef pair<int, ll> Pil;
typedef pair<double, int> Pdi;
typedef tuple<int, int, int> Ti;
typedef tuple<int, int, ll> Tiil;
typedef tuple<ll, int, int> Tlii;
typedef tuple<ll, ll, int> Tlli;

#define Fi first
#define Se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define rep(pos, len) for(int pos=0;pos<len;pos++)
#define repp(pos, len) for(int pos=1;pos<=len;pos++)
#define all(x) x.begin(), x.end()

#define ABS(x) (((x) > 0 ) ? (x) : (-(x)))
#define MAX2(x, y) (((x) > (y)) ? (x) : (y))
#define MIN2(x, y) (((x) < (y)) ? (x) : (y))
#define MAX3(x, y, z) ( (x) > (y)  ? ( (x) > (z) ? (x) : (z)  ) : ( (y) > (z) ? (y) : (z) )  )
#define MIN3(x, y, z) ( (x) < (y)  ? ( (x) < (z) ? (x) : (z)  ) : ( (y) < (z) ? (y) : (z) )  )
#define MID3(val1,val2,val3) MAX2(MIN2(MAX2(val1,val2),val3),MIN2(val1,val2))

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME

#define geti1(X) scanf("%d",&X)
#define geti2(X,Y) scanf("%d%d",&X,&Y)
#define geti3(X,Y,Z) scanf("%d%d%d",&X,&Y,&Z)
#define geti4(X,Y,Z,W) scanf("%d%d%d%d",&X,&Y,&Z,&W)
#define geti(...) GET_MACRO(__VA_ARGS__, geti4, geti3, geti2, geti1) (__VA_ARGS__)

#define getll1(X) scanf("%lld",&X)
#define getll2(X,Y) scanf("%lld%lld",&X,&Y)
#define getll3(X,Y,Z) scanf("%lld%lld%lld",&X,&Y,&Z)
#define getll4(X,Y,Z,W) scanf("%lld%lld%lld%lld",&X,&Y,&Z,&W)
#define getll(...) GET_MACRO(__VA_ARGS__, getll4, getll3, getll2, getll1) (__VA_ARGS__)

#define dout(n) printf("%d\n",n)
#define lldout(n) printf("%lld\n",n)

// 1-index
#define L(x) ((x)<<1)
#define R(x) (((x)<<1)+1)

#define INF 987654321
#define IINF 98765432198765432
#define MOD 1000000007


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cstring>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <unordered_map>
#include <list>
#include <time.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef pair<int, ll> Pil;
typedef pair<double, int> Pdi;
typedef tuple<int, int, int> Ti;
typedef tuple<int, int, ll> Tiil;
typedef tuple<ll, int, int> Tlii;
typedef tuple<ll, ll, int> Tlli;

#define Fi first
#define Se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define rep(pos, len) for(int pos=0;pos<len;pos++)
#define repp(pos, len) for(int pos=1;pos<=len;pos++)
#define all(x) x.begin(), x.end()

#define ABS(x) (((x) > 0 ) ? (x) : (-(x)))
#define MAX2(x, y) (((x) > (y)) ? (x) : (y))
#define MIN2(x, y) (((x) < (y)) ? (x) : (y))
#define MAX3(x, y, z) ( (x) > (y)  ? ( (x) > (z) ? (x) : (z)  ) : ( (y) > (z) ? (y) : (z) )  )
#define MIN3(x, y, z) ( (x) < (y)  ? ( (x) < (z) ? (x) : (z)  ) : ( (y) < (z) ? (y) : (z) )  )
#define MID3(val1,val2,val3) MAX2(MIN2(MAX2(val1,val2),val3),MIN2(val1,val2))

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME

#define geti1(X) scanf("%d",&X)
#define geti2(X,Y) scanf("%d%d",&X,&Y)
#define geti3(X,Y,Z) scanf("%d%d%d",&X,&Y,&Z)
#define geti4(X,Y,Z,W) scanf("%d%d%d%d",&X,&Y,&Z,&W)
#define geti(...) GET_MACRO(__VA_ARGS__, geti4, geti3, geti2, geti1) (__VA_ARGS__)

#define getll1(X) scanf("%lld",&X)
#define getll2(X,Y) scanf("%lld%lld",&X,&Y)
#define getll3(X,Y,Z) scanf("%lld%lld%lld",&X,&Y,&Z)
#define getll4(X,Y,Z,W) scanf("%lld%lld%lld%lld",&X,&Y,&Z,&W)
#define getll(...) GET_MACRO(__VA_ARGS__, getll4, getll3, getll2, getll1) (__VA_ARGS__)

#define dout(n) printf("%d\n",n)
#define lldout(n) printf("%lld\n",n)

// 1-index
#define L(x) ((x)<<1)
#define R(x) (((x)<<1)+1)

#define INF 987654321
#define IINF 98765432198765432
#define MOD 1000000007

const int MAXN = 1e5 + 50;

ll fact[MAXN], finv[MAXN];	// fact[n] = n!, finv[MAXN] = (n!)^(-1)
bool vis[MAXN];
vector<int> pfactor[MAXN];

ll inverse(ll a, ll m) {
    ll m0 = m, t, q;
    ll x0 = 0, x1 = 1;

    if (m == 1)
      return 0;

    while (a > 1) {
        // q is quotient
        q = a / m;
        t = m;

        // m is remainder now, process same as
        // Euclid's algo
        m = a % m, a = t;
        t = x0;
        x0 = x1 - q * x0;
        x1 = t;
    }

    // Make x1 positive
    if (x1 < 0)
       x1 += m0;
    return x1;
}

ll c(int n, int k) {
	return (((fact[n] * finv[k]) % MOD) * finv[n-k]) % MOD;
}

void findPrime() {
	for(int n = 2; n <= 1e5; n++) {
		if(vis[n]) continue;
		vis[n] = true;
		for(int k = 1; k * n <= 1e5; k++) {
			vis[k * n] = true;
			pfactor[k * n].pb(n);
		}
	}
}

void init() {
	fact[0] = 1;
	repp(n, 1e5) fact[n] = (fact[n-1] * n) % MOD;
	finv[0] = 1;
	repp(n, 1e5) finv[n] = inverse(fact[n], MOD);
}

int main() {
	init();
	findPrime();

	int T;
	geti(T);
	while(T--) {
		int n, f;
		geti(n, f);
		ll ans = 0;
		for(int mask = 0; mask < (1 << pfactor[n].size()); mask++) {
			int cnt = 0;
			int tmp = n;
			rep(i, pfactor[n].size()) {
				if((mask >> i) & 1) {
					tmp /= pfactor[n][i];
					cnt++;
				}
			}
			if(cnt & 1) {
				ans = (ans - c(tmp - 1, f - 1) + MOD) % MOD;
			} else {
				ans = (ans + c(tmp - 1, f - 1)) % MOD;
			}
		}

		lldout(ans);
	}
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cstring>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <unordered_map>
#include <list>
#include <time.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef pair<int, ll> Pil;
typedef pair<double, int> Pdi;
typedef tuple<int, int, int> Ti;
typedef tuple<int, int, ll> Tiil;
typedef tuple<ll, int, int> Tlii;
typedef tuple<ll, ll, int> Tlli;

#define Fi first
#define Se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define rep(pos, len) for(int pos=0;pos<len;pos++)
#define repp(pos, len) for(int pos=1;pos<=len;pos++)
#define all(x) x.begin(), x.end()

#define ABS(x) (((x) > 0 ) ? (x) : (-(x)))
#define MAX2(x, y) (((x) > (y)) ? (x) : (y))
#define MIN2(x, y) (((x) < (y)) ? (x) : (y))
#define MAX3(x, y, z) ( (x) > (y)  ? ( (x) > (z) ? (x) : (z)  ) : ( (y) > (z) ? (y) : (z) )  )
#define MIN3(x, y, z) ( (x) < (y)  ? ( (x) < (z) ? (x) : (z)  ) : ( (y) < (z) ? (y) : (z) )  )
#define MID3(val1,val2,val3) MAX2(MIN2(MAX2(val1,val2),val3),MIN2(val1,val2))

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME

#define geti1(X) scanf("%d",&X)
#define geti2(X,Y) scanf("%d%d",&X,&Y)
#define geti3(X,Y,Z) scanf("%d%d%d",&X,&Y,&Z)
#define geti4(X,Y,Z,W) scanf("%d%d%d%d",&X,&Y,&Z,&W)
#define geti(...) GET_MACRO(__VA_ARGS__, geti4, geti3, geti2, geti1) (__VA_ARGS__)

#define getll1(X) scanf("%lld",&X)
#define getll2(X,Y) scanf("%lld%lld",&X,&Y)
#define getll3(X,Y,Z) scanf("%lld%lld%lld",&X,&Y,&Z)
#define getll4(X,Y,Z,W) scanf("%lld%lld%lld%lld",&X,&Y,&Z,&W)
#define getll(...) GET_MACRO(__VA_ARGS__, getll4, getll3, getll2, getll1) (__VA_ARGS__)

#define dout(n) printf("%d\n",n)
#define lldout(n) printf("%lld\n",n)

// 1-index
#define L(x) ((x)<<1)
#define R(x) (((x)<<1)+1)

#define INF 987654321
#define IINF 98765432198765432
#define MOD 1000000007

const int MAXN = 1e5 + 50;

ll fact[MAXN], finv[MAXN];	// fact[n] = n!, finv[MAXN] = (n!)^(-1)
bool vis[MAXN];
vector<int> pfactor[MAXN];

ll inverse(ll a, ll m) {
    ll m0 = m, t, q;
    ll x0 = 0, x1 = 1;

    if (m == 1)
      return 0;

    while (a > 1) {
        // q is quotient
        q = a / m;
        t = m;

        // m is remainder now, process same as
        // Euclid's algo
        m = a % m, a = t;
        t = x0;
        x0 = x1 - q * x0;
        x1 = t;
    }

    // Make x1 positive
    if (x1 < 0)
       x1 += m0;
    return x1;
}

ll c(int n, int k) {
	if(n < k) return 0;
	return (((fact[n] * finv[k]) % MOD) * finv[n-k]) % MOD;
}

void findPrime() {
	for(int n = 2; n <= 1e5; n++) {
		if(vis[n]) continue;
		vis[n] = true;
		for(int k = 1; k * n <= 1e5; k++) {
			vis[k * n] = true;
			pfactor[k * n].pb(n);
		}
	}
}

void init() {
	fact[0] = 1;
	repp(n, 1e5) fact[n] = (fact[n-1] * n) % MOD;
	finv[0] = 1;
	repp(n, 1e5) finv[n] = inverse(fact[n], MOD);
}

int main() {
	init();
	findPrime();

	int T;
	geti(T);
	while(T--) {
		int n, f;
		geti(n, f);
		ll ans = 0;
		for(int mask = 0; mask < (1 << pfactor[n].size()); mask++) {
			int cnt = 0;
			int tmp = n;
			rep(i, pfactor[n].size()) {
				if((mask >> i) & 1) {
					tmp /= pfactor[n][i];
					cnt++;
				}
			}
			if(cnt & 1) {
				ans = (ans - c(tmp - 1, f - 1) + MOD) % MOD;
			} else {
				ans = (ans + c(tmp - 1, f - 1)) % MOD;
			}
		}

		printf("%d\n", (int)ans);
	}
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cstring>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <unordered_map>
#include <list>
#include <time.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef pair<int, ll> Pil;
typedef pair<double, int> Pdi;
typedef tuple<int, int, int> Ti;
typedef tuple<int, int, ll> Tiil;
typedef tuple<ll, int, int> Tlii;
typedef tuple<ll, ll, int> Tlli;

#define Fi first
#define Se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define rep(pos, len) for(int pos=0;pos<len;pos++)
#define repp(pos, len) for(int pos=1;pos<=len;pos++)
#define all(x) x.begin(), x.end()

#define ABS(x) (((x) > 0 ) ? (x) : (-(x)))
#define MAX2(x, y) (((x) > (y)) ? (x) : (y))
#define MIN2(x, y) (((x) < (y)) ? (x) : (y))
#define MAX3(x, y, z) ( (x) > (y)  ? ( (x) > (z) ? (x) : (z)  ) : ( (y) > (z) ? (y) : (z) )  )
#define MIN3(x, y, z) ( (x) < (y)  ? ( (x) < (z) ? (x) : (z)  ) : ( (y) < (z) ? (y) : (z) )  )
#define MID3(val1,val2,val3) MAX2(MIN2(MAX2(val1,val2),val3),MIN2(val1,val2))

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME

#define geti1(X) scanf("%d",&X)
#define geti2(X,Y) scanf("%d%d",&X,&Y)
#define geti3(X,Y,Z) scanf("%d%d%d",&X,&Y,&Z)
#define geti4(X,Y,Z,W) scanf("%d%d%d%d",&X,&Y,&Z,&W)
#define geti(...) GET_MACRO(__VA_ARGS__, geti4, geti3, geti2, geti1) (__VA_ARGS__)

#define getll1(X) scanf("%lld",&X)
#define getll2(X,Y) scanf("%lld%lld",&X,&Y)
#define getll3(X,Y,Z) scanf("%lld%lld%lld",&X,&Y,&Z)
#define getll4(X,Y,Z,W) scanf("%lld%lld%lld%lld",&X,&Y,&Z,&W)
#define getll(...) GET_MACRO(__VA_ARGS__, getll4, getll3, getll2, getll1) (__VA_ARGS__)

#define dout(n) printf("%d\n",n)
#define lldout(n) printf("%lld\n",n)

// 1-index
#define L(x) ((x)<<1)
#define R(x) (((x)<<1)+1)

#define INF 987654321
#define IINF 98765432198765432
#define MOD 1000000007

const int MAXN = 1e5 + 50;

ll fact[MAXN], finv[MAXN];	// fact[n] = n!, finv[MAXN] = (n!)^(-1)
bool vis[MAXN];
vector<int> pfactor[MAXN];

ll inverse(ll a, ll m) {
    ll m0 = m, t, q;
    ll x0 = 0, x1 = 1;

    if (m == 1)
      return 0;

    while (a > 1) {
        // q is quotient
        q = a / m;
        t = m;

        // m is remainder now, process same as
        // Euclid's algo
        m = a % m, a = t;
        t = x0;
        x0 = x1 - q * x0;
        x1 = t;
    }

    // Make x1 positive
    if (x1 < 0)
       x1 += m0;
    return x1;
}

ll c(int n, int k) {
	return (((fact[n] * finv[k]) % MOD) * finv[n-k]) % MOD;
}

void findPrime() {
	for(int n = 2; n <= 1e5; n++) {
		if(vis[n]) continue;
		vis[n] = true;
		for(int k = 2; k * n <= 1e5; k++) {
			vis[k * n] = true;
			pfactor[k * n].pb(n);
		}
	}
}

void init() {
	fact[0] = 1;
	repp(n, 1e5) fact[n] = (fact[n-1] * n) % MOD;
	finv[0] = 1;
	repp(n, 1e5) finv[n] = inverse(fact[n], MOD);
}

int main() {
	init();
	findPrime();

	int T;
	geti(T);
	while(T--) {
		int n, f;
		geti(n, f);
		ll ans = 0;
		for(int mask = 0; mask < (1 << pfactor[n].size()); mask++) {
			int cnt = 0;
			int tmp = n;
			rep(i, pfactor[n].size()) {
				if((mask >> i) & 1) {
					tmp /= pfactor[n][i];
					cnt++;
				}
			}
			if(cnt & 1) {
				ans = (ans - c(tmp - 1, f - 1) + MOD) % MOD;
			} else {
				ans = (ans + c(tmp - 1, f - 1)) % MOD;
			}
		}

		lldout(ans);
	}
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cstring>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <unordered_map>
#include <list>
#include <time.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef pair<int, ll> Pil;
typedef pair<double, int> Pdi;
typedef tuple<int, int, int> Ti;
typedef tuple<int, int, ll> Tiil;
typedef tuple<ll, int, int> Tlii;
typedef tuple<ll, ll, int> Tlli;

#define Fi first
#define Se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define rep(pos, len) for(int pos=0;pos<len;pos++)
#define repp(pos, len) for(int pos=1;pos<=len;pos++)
#define all(x) x.begin(), x.end()

#define ABS(x) (((x) > 0 ) ? (x) : (-(x)))
#define MAX2(x, y) (((x) > (y)) ? (x) : (y))
#define MIN2(x, y) (((x) < (y)) ? (x) : (y))
#define MAX3(x, y, z) ( (x) > (y)  ? ( (x) > (z) ? (x) : (z)  ) : ( (y) > (z) ? (y) : (z) )  )
#define MIN3(x, y, z) ( (x) < (y)  ? ( (x) < (z) ? (x) : (z)  ) : ( (y) < (z) ? (y) : (z) )  )
#define MID3(val1,val2,val3) MAX2(MIN2(MAX2(val1,val2),val3),MIN2(val1,val2))

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME

#define geti1(X) scanf("%d",&X)
#define geti2(X,Y) scanf("%d%d",&X,&Y)
#define geti3(X,Y,Z) scanf("%d%d%d",&X,&Y,&Z)
#define geti4(X,Y,Z,W) scanf("%d%d%d%d",&X,&Y,&Z,&W)
#define geti(...) GET_MACRO(__VA_ARGS__, geti4, geti3, geti2, geti1) (__VA_ARGS__)

#define getll1(X) scanf("%lld",&X)
#define getll2(X,Y) scanf("%lld%lld",&X,&Y)
#define getll3(X,Y,Z) scanf("%lld%lld%lld",&X,&Y,&Z)
#define getll4(X,Y,Z,W) scanf("%lld%lld%lld%lld",&X,&Y,&Z,&W)
#define getll(...) GET_MACRO(__VA_ARGS__, getll4, getll3, getll2, getll1) (__VA_ARGS__)

#define dout(n) printf("%d\n",n)
#define lldout(n) printf("%lld\n",n)

// 1-index
#define L(x) ((x)<<1)
#define R(x) (((x)<<1)+1)

#define INF 987654321
#define IINF 98765432198765432
#define MOD 1000000007

const int MAXN = 2e5 + 50;
bool input[MAXN];
int cnt[MAXN], dis[MAXN], m;
vector<int> adj[MAXN], rev[MAXN], path[MAXN], ans;

int gcd(int a, int b) {
	if(a < b) swap(a, b);
	if(b == 0) return a;
	return gcd(b, a % b);
}

int inverse(int a, int m) {
    int m0 = m, t, q;
    int x0 = 0, x1 = 1;

    if (m == 1)
      return 0;

    while (a > 1) {
        // q is quotient
        q = a / m;
        t = m;

        // m is remainder now, process same as
        // Euclid's algo
        m = a % m, a = t;
        t = x0;
        x0 = x1 - q * x0;
        x1 = t;
    }

    // Make x1 positive
    if (x1 < 0)
       x1 += m0;
    return x1;
}

// find x: ax == b (m)
int func(int a, int b) {
	int g = gcd(a, m);
	return ((ll)(b/g) * (ll)inverse(a/g, m/g)) % m;
}

void rev_dfs(int x) {
	ans.insert(ans.end(), path[x].begin(), path[x].end());
	if(x == 1) return;
	for(auto &p : rev[x]) {
		if(dis[p] + cnt[x] == dis[x]) {
			rev_dfs(p);
			break;
		}
	}
}

int main() {
	int n;
	geti(n, m);

	if(m == 1) {
		if(n == 0) {
			printf("1\n0");
			return 0;
		} else {
			dout(0);
			return 0;
		}
	}

	rep(i, n) {
		int tmp;
		geti(tmp);
		input[tmp] = true;
	}

	repp(d, m) {
		if(m % d != 0) continue;
		repp(k, m/d) {
			if(!input[k * d] && gcd(k * d, m) == d) {
				cnt[d]++;
				path[d].pb(k * d);
			}
			if(m % (k * d) == 0 && k > 1) {
				adj[d].pb(k * d);
				rev[k * d].pb(d);
			}
		}
		/*
		printf("<%d>\n", d);
		for(auto &e : path[d]) printf("%d ", e);
		printf("\n");
		*/
		reverse(path[d].begin(), path[d].end());
	}

	// repp(i, m) printf("%d %d\n", i, cnt[i]);

	priority_queue<Pi> pq;
	dis[1] = cnt[1];
	pq.push({dis[1], 1});

	while(!pq.empty()) {
		int x = pq.top().Se;
		int d = pq.top().Fi;
		pq.pop();

		if(d < dis[x]) continue;
		dis[x] = d;
		for(auto &c : adj[x]) {
			if(dis[c] <= dis[x] + cnt[c]) {
				dis[c] = dis[x] + cnt[c];
				pq.push({dis[c], c});
			}
		}
	}

	dout(dis[m]);
	rev_dfs(m);
	reverse(ans.begin(), ans.end());
	if(ans.empty()) return 0;
	printf("%d ", ans[0]);

	for(int i = 0; i < ans.size() - 1; i++) {
		printf("%d ", func(ans[i], ans[i+1]));
		//printf("%d ", ans[i+1]);
	}
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cstring>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <unordered_map>
#include <list>
#include <time.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef pair<int, ll> Pil;
typedef pair<double, int> Pdi;
typedef tuple<int, int, int> Ti;
typedef tuple<int, int, ll> Tiil;
typedef tuple<ll, int, int> Tlii;
typedef tuple<ll, ll, int> Tlli;

#define Fi first
#define Se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define rep(pos, len) for(int pos=0;pos<len;pos++)
#define repp(pos, len) for(int pos=1;pos<=len;pos++)
#define all(x) x.begin(), x.end()

#define ABS(x) (((x) > 0 ) ? (x) : (-(x)))
#define MAX2(x, y) (((x) > (y)) ? (x) : (y))
#define MIN2(x, y) (((x) < (y)) ? (x) : (y))
#define MAX3(x, y, z) ( (x) > (y)  ? ( (x) > (z) ? (x) : (z)  ) : ( (y) > (z) ? (y) : (z) )  )
#define MIN3(x, y, z) ( (x) < (y)  ? ( (x) < (z) ? (x) : (z)  ) : ( (y) < (z) ? (y) : (z) )  )
#define MID3(val1,val2,val3) MAX2(MIN2(MAX2(val1,val2),val3),MIN2(val1,val2))

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME

#define geti1(X) scanf("%d",&X)
#define geti2(X,Y) scanf("%d%d",&X,&Y)
#define geti3(X,Y,Z) scanf("%d%d%d",&X,&Y,&Z)
#define geti4(X,Y,Z,W) scanf("%d%d%d%d",&X,&Y,&Z,&W)
#define geti(...) GET_MACRO(__VA_ARGS__, geti4, geti3, geti2, geti1) (__VA_ARGS__)

#define getll1(X) scanf("%lld",&X)
#define getll2(X,Y) scanf("%lld%lld",&X,&Y)
#define getll3(X,Y,Z) scanf("%lld%lld%lld",&X,&Y,&Z)
#define getll4(X,Y,Z,W) scanf("%lld%lld%lld%lld",&X,&Y,&Z,&W)
#define getll(...) GET_MACRO(__VA_ARGS__, getll4, getll3, getll2, getll1) (__VA_ARGS__)

#define dout(n) printf("%d\n",n)
#define lldout(n) printf("%lld\n",n)

// 1-index
#define L(x) ((x)<<1)
#define R(x) (((x)<<1)+1)

#define INF 987654321
#define IINF 98765432198765432
#define MOD 1000000007

const int MAXN = 1e5 + 50;

ll fact[MAXN], finv[MAXN];	// fact[n] = n!, finv[MAXN] = (n!)^(-1)
bool vis[MAXN];
vector<int> pfactor[MAXN];

ll inverse(ll a, ll m) {
    ll m0 = m, t, q;
    ll x0 = 0, x1 = 1;

    if (m == 1)
      return 0;

    while (a > 1) {
        // q is quotient
        q = a / m;
        t = m;

        // m is remainder now, process same as
        // Euclid's algo
        m = a % m, a = t;
        t = x0;
        x0 = x1 - q * x0;
        x1 = t;
    }

    // Make x1 positive
    if (x1 < 0)
       x1 += m0;
    return x1;
}

ll c(int n, int k) {
	return (((fact[n] * finv[k]) % MOD) * finv[n-k]) % MOD;
}

void findPrime() {
	for(int n = 2; n <= 1e5; n++) {
		if(vis[n]) continue;
		vis[n] = true;
		for(int k = 1; k * n <= 1e5; k++) {
			vis[k * n] = true;
			pfactor[k * n].pb(n);
		}
	}
}

void init() {
	fact[0] = 1;
	repp(n, 1e5) fact[n] = (fact[n-1] * n) % MOD;
	finv[0] = 1;
	repp(n, 1e5) finv[n] = inverse(fact[n], MOD);
}

int main() {
	init();
	findPrime();

	int T;
	geti(T);
	while(T--) {
		int n, f;
		geti(n, f);
		ll ans = 0;
		for(int mask = 0; mask < (1 << pfactor[n].size()); mask++) {
			int cnt = 0;
			int tmp = n;
			rep(i, pfactor[n].size()) {
				if((mask >> i) & 1) {
					tmp /= pfactor[n][i];
					cnt++;
				}
			}
			if(cnt & 1) {
				ans = (ans - c(tmp - 1, f - 1) + MOD) % MOD;
			} else {
				ans = (ans + c(tmp - 1, f - 1)) % MOD;
			}
		}

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


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

const int mod = 1000000007;

int po(int x, int n) {
    int ret = 1;
    while(n) {
        if(n & 1) ret = (ll)ret * x % mod;
        x = (ll)x * x % mod;
        n >>= 1;
    }
    return ret;
}

int modInv(int x) { return po(x, mod - 2); }

vector<int> fac, invf;

void getFactorial() {
    fac.resize(1000000);
    fac[0] = 1;
    for(int i = 1; i < 1000000; i++) {
        fac[i] = (ll)i * fac[i - 1] % mod;
    }
    invf.resize(1000000);
    for(int i = 0; i < 1000000; i++) {
        invf[i] = modInv(fac[i]);
    }
}

int comb(int n, int k) {
    return (ll)( (ll)fac[n] * invf[k] % mod ) * invf[n - k] % mod;
}

int H(int n, int k) { return comb(n + k - 1, k); }

int Q, N, F;

vector<int> dv;
map<int, int> dp;

int main() {
    getFactorial();

    scanf("%d", &Q);

    for(int i = 0; i < Q; i++) {
        scanf("%d %d", &N, &F);

        dv.clear();
        for(int j = 1; j <= sqrt(N); j++) {
            if(N % j == 0) {
                dv.push_back(j);
                if(j*j != N) dv.push_back(N / j);
            }
        }

        sort(dv.begin(), dv.end());

        dp.clear();
        for(int i = dv.size() - 1; i >= 0; i--) {
            dp[ dv[i] ] = N / dv[i] >= F? H(F, N / dv[i] - F) : 0;

            int mul = 2;
            while(dv[i] * mul <= N) {
                dp[ dv[i] ] -= dp[ dv[i] * mul ];
                dp[ dv[i] ] = (dp[ dv[i] ] % mod + mod) % mod;
                mul++;
            }
        }

        printf("%d\n", dp[1]);
    }
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

const int mod = 1000000007;

int po(int x, int n) {
    int ret = 1;
    while(n) {
        if(n & 1) ret = (ll)ret * x % mod;
        x = (ll)x * x % mod;
        n >>= 1;
    }
    return ret;
}

int modInv(int x) { return po(x, mod - 2); }

vector<int> fac, invf;

void getFactorial() {
    fac.resize(1000000);
    fac[0] = 1;
    for(int i = 1; i < 1000000; i++) {
        fac[i] = (ll)i * fac[i - 1] % mod;
    }
    invf.resize(1000000);
    for(int i = 0; i < 1000000; i++) {
        invf[i] = modInv(fac[i]);
    }
}

int comb(int n, int k) {
    return (ll)( (ll)fac[n] * invf[k] % mod ) * invf[n - k] % mod;
}

int H(int n, int k) { return comb(n + k - 1, k); }

vector<int> pr, pchk;

void getPrime() {
    pchk = vector<int>(1000000, 0);
    for(int i = 2; i < 1000000; i++) {
        if(pchk[i]) continue;
        pr.push_back(i);
        int mul = 2;
        while(i * mul < 1000000) {
            pchk[i * mul] = 1;
            mul++;
        }
    }
}

vector<int> mo;

void getMobius() {
    mo.resize(1000000);
    mo[1] = 1;
    for(int i = 2; i < 1000000; i++) {
        bool zero = false;
        int n = i;
        int cnt = 0;
        for(int j = 0; j < pr.size() && pr[j] <= sqrt(n); j++) {
            if(n % pr[j] == 0) {
                if(n % (pr[j] * pr[j]) == 0) {
                    mo[i] = 0;
                    zero = true;
                    break;
                }
                else {
                    n /= pr[j];
                    cnt++;
                }
            }
        }
        if(n) cnt++;
        if(!zero) mo[i] = cnt % 2? -1 : 1;
    }
}

int Q, N, F;

vector<int> dv;

int main() {
    getFactorial();
    getPrime();
    getMobius();

    scanf("%d", &Q);

    for(int i = 0; i < Q; i++) {
        scanf("%d %d", &N, &F);

        dv.clear();
        for(int j = 1; j <= sqrt(N); j++) {
            if(N % j == 0) {
                dv.push_back(j);
                if(j*j != N) dv.push_back(N / j);
            }
        }

        int ans = 0;
        for(int j = 0; j < dv.size(); j++) {
            ans += mo[ dv[j] ] * (N / dv[j] >= F? H(F, N / dv[j] - F) : 0);
            ans = (ans % mod + mod) % mod;
        }
        printf("%d\n", ans);
    }
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

const int mod = 1000000007;

int po(int x, int n) {
    int ret = 1;
    while(n) {
        if(n & 1) ret = (ll)ret * x % mod;
        x = (ll)x * x % mod;
        n >>= 1;
    }
    return ret;
}

int modInv(int x) { return po(x, mod - 2); }

vector<int> fac, invf;

void getFactorial() {
    fac.resize(1000000);
    fac[0] = 1;
    for(int i = 1; i < 1000000; i++) {
        fac[i] = (ll)i * fac[i - 1] % mod;
    }
    invf.resize(1000000);
    for(int i = 0; i < 1000000; i++) {
        invf[i] = modInv(fac[i]);
    }
}

int comb(int n, int k) {
    return (ll)( (ll)fac[n] * invf[k] % mod ) * invf[n - k] % mod;
}

int H(int n, int k) { return comb(n + k - 1, k); }

int Q, N, F;

vector<int> dv, dp;

int main() {
    getFactorial();

    scanf("%d", &Q);

    dp.resize(1000000);

    for(int i = 0; i < Q; i++) {
        scanf("%d %d", &N, &F);

        dv.clear();
        for(int j = 1; j <= sqrt(N); j++) {
            if(N % j == 0) {
                dv.push_back(j);
                if(j*j != N) dv.push_back(N / j);
            }
        }

        sort(dv.begin(), dv.end());

        dp.clear();
        for(int i = dv.size() - 1; i >= 0; i--) {
            dp[ dv[i] ] = N / dv[i] >= F? H(F, N / dv[i] - F) : 0;

            int mul = 2;
            while(dv[i] * mul <= N) {
                if(N % (dv[i] * mul) != 0) {
                    mul++;
                    continue;
                }
                dp[ dv[i] ] -= dp[ dv[i] * mul ];
                dp[ dv[i] ] = (dp[ dv[i] ] % mod + mod) % mod;
                mul++;
            }
        }

        printf("%d\n", dp[1]);
    }
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

const int mod = 1000000007;

int po(int x, int n) {
    int ret = 1;
    while(n) {
        if(n & 1) ret = (ll)ret * x % mod;
        x = (ll)x * x % mod;
        n >>= 1;
    }
    return ret;
}

int modInv(int x) { return po(x, mod - 2); }

vector<int> fac, invf;

void getFactorial() {
    fac.resize(1000000);
    fac[0] = 1;
    for(int i = 1; i < 1000000; i++) {
        fac[i] = (ll)i * fac[i - 1] % mod;
    }
    invf.resize(1000000);
    for(int i = 0; i < 1000000; i++) {
        invf[i] = modInv(fac[i]);
    }
}

int comb(int n, int k) {
    return (ll)( (ll)fac[n] * invf[k] % mod ) * invf[n - k] % mod;
}

int H(int n, int k) { return comb(n + k - 1, k); }

int Q, N, F;

vector<int> dv;
map<int, int> dp;

int main() {
    getFactorial();

    scanf("%d", &Q);

    for(int i = 0; i < Q; i++) {
        scanf("%d %d", &N, &F);

        dv.clear();
        for(int j = 1; j <= sqrt(N); j++) {
            if(N % j == 0) {
                dv.push_back(j);
                if(j*j != N) dv.push_back(N / j);
            }
        }

        sort(dv.begin(), dv.end());

        dp.clear();
        for(int i = dv.size() - 1; i >= 0; i--) {
            dp[ dv[i] ] = N / dv[i] >= F? H(F, N / dv[i] - F) : 0;

            int mul = 2;
            while(dv[i] * mul < N) {
                dp[ dv[i] ] -= dp[ dv[i] * mul ];
                dp[ dv[i] ] = (dp[ dv[i] ] % mod + mod) % mod;
                mul++;
            }
        }

        printf("%d\n", dp[1]);
    }
}


//#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

#define boost ios::sync_with_stdio(0); cin.tie(0)

#define fi first
#define se second

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;

const int N = 1e5 + 5;
const int MOD = 1000000007;

/***************************************************************************/

ll power(ll a, ll n, ll m) {
	if(n == 0) return 1;
	ll p = power(a, n/2, m);
	p = (p * p) % m;
	if(n & 1) p = (p * a) % m;
	return p;
}

ll fact[N], ifact[N];

void calculateFact() {

	fact[0] = 1;

	for(int i=1; i<N; i++) {
		fact[i] = (i * fact[i-1]) % MOD;
	}
	ifact[N-1] = power(fact[N-1], MOD-2, MOD);

	for(int i=N-1; i>=1; i--) {
		ifact[i-1] = (i * ifact[i]) % MOD;
	}
}

ll nck(int n, int k) {

	if(n < k || k < 0) return 0;

	ll ans = fact[n];
	ans = (ans * ifact[k]) % MOD;
	ans = (ans * ifact[n-k]) % MOD;

	return ans;
}

vector<int> divs[N];
ll val[N];

int main() {

	boost;
	calculateFact();

	for(int i=1; i<N; i++) {
		for(int j=(i<<1); j<N; j+=i) {
			divs[j].push_back(i);
		}
	}

	int q; cin>>q;
	while(q--) {
		int n, f;
		cin>>n>>f;

		ll ans = nck(n-1, n-f);

		for(auto it : divs[n]) {
			val[it] = nck(it-1, it-f);
			for(auto d : divs[it]) {
				val[it] -= val[d];
			}
			ans -= val[it];
		}

		ans %= MOD; if(ans < 0) ans += MOD;
		cout<<ans<<"\n";
	}

	return 0;
}


//#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

#define boost ios::sync_with_stdio(0); cin.tie(0)

#define fi first
#define se second

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;

const int N = 1e5 + 5;
const int MOD = 1000000007;

/***************************************************************************/

ll power(ll a, ll n, ll m) {
	if(n == 0) return 1;
	ll p = power(a, n/2, m);
	p = (p * p) % m;
	if(n & 1) p = (p * a) % m;
	return p;
}

ll fact[N], ifact[N];

void calculateFact() {

	fact[0] = 1;

	for(int i=1; i<N; i++) {
		fact[i] = (i * fact[i-1]) % MOD;
	}
	ifact[N-1] = power(fact[N-1], MOD-2, MOD);

	for(int i=N-1; i>=1; i--) {
		ifact[i-1] = (i * ifact[i]) % MOD;
	}
}

ll nck(int n, int k) {

	if(n < k) return 0;

	ll ans = fact[n];
	ans = (ans * ifact[k]) % MOD;
	ans = (ans * ifact[n-k]) % MOD;

	return ans;
}

vector<int> divs[N];
ll val[N];

int main() {

	boost;
	calculateFact();

	for(int i=1; i<N; i++) {
		for(int j=(i<<1); j<N; j+=i) {
			divs[j].push_back(i);
		}
	}

	int q; cin>>q;
	while(q--) {
		int n, f;
		cin>>n>>f;

		ll ans = nck(n-1, n-f);

		for(auto it : divs[n]) {
			val[it] = nck(it-1, it-f);
			for(auto d : divs[it]) {
				val[it] -= val[d];
			}
			ans -= val[it];
		}

		ans %= MOD; if(ans < 0) ans += MOD;
		cout<<ans<<"\n";
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
int mpow(int base, int exp);
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================
ll fac[N], ifac[N];
vi g[N];
int a[N];
ll ff(int n, int f){
	n--, f--;
	if(n<f)return 0;
	ll ans = fac[n];
	ans *= ifac[f];
	ans %= mod;
	ans *= ifac[n-f];
	ans %= mod;
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int i,n,m,k,j,f;
	fac[0] = fac[1] = 1;  ifac[0] = ifac[1] = 1;
	Fo(i, 2, N) fac[i] = (fac[i-1]*1LL*i)%mod;
	Fo(i, 2, N) ifac[i] = (ifac[i-1]*1LL*mpow(i, mod-2))%mod;
	int q;
	cin>>q;
	while(q--){
		cin>>n>>f;
		if(f==1){
			cout<<1<<endl;
			continue;
		}
		ll ans = ff(n, f);
		Fo(i, 2, n){
			if(i*i > n) break;
			if(i*i == n) {
				ans -= ff(i, f);
				if(ans < 0) ans += mod;
			}
			if(n%i == 0) {
				ans -= ff(i, f);
				if(ans < 0) ans += mod;
				ans -= ff(n/i, f);
				if(ans < 0) ans += mod;
			}
		}
		cout << ans << endl;
	}
	return 0;
}
int mpow(int base, int exp) {
	base %= mod;
	int result = 1;
	while (exp > 0) {
	if (exp & 1) result = ((ll)result * base) % mod;
	base = ((ll)base * base) % mod;
	exp >>= 1;
	}
	return result;
}


#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
int mpow(int base, int exp);
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================
ll fac[N], ifac[N];
vi g[N];
int a[N];

ll ff(int n, int f){
	n--, f--;
	if(n<f)return 0;
	ll ans = fac[n];
	ans *= ifac[f];
	ans %= mod;
	ans *= ifac[n-f];
	ans %= mod;
	return ans;
}
vi p, sq, mu;
void pre(){
	int i, j;
	p.resize(N, 1);
	sq.resize(N, 0);
	mu.resize(N, 0);
	p[0] = p[1] = 0;
	Fo(i, 2, N){
		if(p[i]){
			for(j=2*i; j<N;j+=i)
				p[j] = 0;
		}
	}
	Fo(i, 1, N){
		for(j=i; j<N; j+=i){
			g[j].pb(i);
		}
	}

	Fo(i, 2, N){
		if(i*1LL*i > N) break;
		int x = i*i;
		for(j=x; j<N; j+=x){
			sq[j] = 1;
		}
	}

	mu[1] = 1;
	Fo(i, 2, N){
		if(sq[i]==1) continue;
		int tot = 0;
		for(int x: g[i]) tot += p[x];
		mu[i] = (tot&1)?-1:1;
	}

}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int i,n,m,k,j,f;
	pre();
	fac[0] = fac[1] = 1;  ifac[0] = ifac[1] = 1;
	Fo(i, 2, N) fac[i] = (fac[i-1]*1LL*i)%mod;
	Fo(i, 2, N) ifac[i] = (ifac[i-1]*1LL*mpow(i, mod-2))%mod;
	int q;
	cin>>q;
	while(q--){
		cin>>n>>f;
		if(f==1){
			if(n==1) cout<<1<<endl;
			else cout<<0<<endl;
			continue;
		}
		ll ans = 0;
		for(int x: g[n]) {
			ans += (mu[n/x]*ff(x, f))%mod;
			if(ans<0) ans += mod;
			if(ans >= mod) ans -= mod;
		}
		cout << ans << endl;
	}
	return 0;
}
int mpow(int base, int exp) {
	base %= mod;
	int result = 1;
	while (exp > 0) {
	if (exp & 1) result = ((ll)result * base) % mod;
	base = ((ll)base * base) % mod;
	exp >>= 1;
	}
	return result;
}


#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
int mpow(int base, int exp);
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================
ll fac[N], ifac[N];
vi g[N];
int a[N];
ll ff(int n, int f){
	n--, f--;
	if(n<f)return 0;
	ll ans = fac[n];
	ans *= ifac[f];
	ans %= mod;
	ans *= ifac[n-f];
	ans %= mod;
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int i,n,m,k,j,f;
	fac[0] = fac[1] = 1;  ifac[0] = ifac[1] = 1;
	Fo(i, 2, N) fac[i] = (fac[i-1]*1LL*i)%mod;
	Fo(i, 2, N) ifac[i] = (ifac[i-1]*1LL*mpow(i, mod-2))%mod;
	int q;
	cin>>q;
	while(q--){
		cin>>n>>f;
		if(f==1){
			if(n==1) cout<<1<<endl;
			else cout<<0<<endl;
			continue;
		}
		ll ans = ff(n, f);
		Fo(i, 2, n){
			if(i*i > n) break;
			if(i*i == n) {
				ans -= ff(i, f);
				if(ans < 0) ans += mod;
			}
			if(n%i == 0) {
				ans -= ff(i, f);
				if(ans < 0) ans += mod;
				ans -= ff(n/i, f);
				if(ans < 0) ans += mod;
			}
		}
		cout << ans << endl;
	}
	return 0;
}
int mpow(int base, int exp) {
	base %= mod;
	int result = 1;
	while (exp > 0) {
	if (exp & 1) result = ((ll)result * base) % mod;
	base = ((ll)base * base) % mod;
	exp >>= 1;
	}
	return result;
}


#include <bits/stdc++.h>
using namespace std;
#define forr(i, a, b) for(int i = (int) a; i < (int) b; i++)
#define forn(i, n) forr(i, 0, n)
#define pb push_back
typedef long long ll;
const int MAXN = 100500, MOD = 1e9+7;

void hallar_div(int n, vector<int> &X){
	X.clear(); int p;
	for(p = 1; p*p < n; p++)if(!(n%p))X.pb(p), X.pb(n/p);
	if(p*p == n)X.pb(p);
	sort(X.begin(), X.end());
}

int n, f, q;
ll S[MAXN];
vector<int> D;

ll expmod(ll b, ll e){
    if(!e) return 1;
    return (e%2 ? b : 1) * expmod(b*b%MOD, e/2) %MOD;
}
ll F[MAXN], FI[MAXN];
ll CMB(ll n, ll k){
    if(k < 0)return 0;
    if(k > n)return 0;
    return (F[n] * FI[k] % MOD) * FI[n-k] % MOD;
}

void solve(int m, int k){
	/*ll ans = CMB(n-1, k-1);
	vector<int> A;
	for(int i = 0; D[i] < n; i++){
        if(!(n%D[i]))A.pb(D[i]);
	}
	forn(i, A.size()) ans = (ans - S[A[i]])%MOD;*/
	S[m] = (S[m] + CMB(m-1, k-1)) %MOD;
	for(int i = 2; i*m <= n; i++)S[i*m] = (S[i*m] - S[m] + MOD) %MOD;
	//printf("La solucion para %d es %lld\n", m, S[m]);
}

int main(){
	F[0] = FI[0] = 1;
	forr(i, 1, MAXN)F[i] = F[i-1] * i % MOD;
	forr(i, 1, MAXN)FI[i] = FI[i-1] * expmod(i, MOD-2) % MOD;
	//cout << "Que le pasa a mi camion" << endl;
	while(cin >> q){
		forn(cs, q){
			forn(i, MAXN)S[i] = 0;
			scanf("%d %d", &n, &f);
			//cout << "Leimos bien." << endl;
			hallar_div(n, D);
			//printf("Los divisores de n son:"); forn(i, D.size())printf(" %d", D[i]); puts("");
			forn(i, D.size())solve(D[i], f);
			printf("%lld\n", S[n]);
		}
	}
}


#include <bits/stdc++.h>
using namespace std;
#define forr(i, a, b) for(int i = (int) a; i < (int) n; i++)
#define forn(i, n) forr(i, 0, n)
typedef long long ll;
const int MAXN = -1, MOD = 1e9+7;

void hallar_div(int n, vector<int> &X){
	X.clear(); int p;
	for(p = 1; p*p < n; p++)if(!(n%p))X.pb(p), X.pb(n/p);
	if(p*p == n)X.pb(p);
	sort(X.begin(), X.end());
}

int n, f, q;
ll S[MAXN];
vector<int> D;
const int MAXC = 1000;
ll C[MAXC+1][MAXC+1];

void solve(int n, int k){
	ll ans = 0;
	vector<int> A;
	hallar_div(n, A);
	ans = C[n-1][k-1];///	qAAAAAAAAAAAAAAAAAFDASFGEEEFGEW
	forn(i, A.size()) ans = (ans - S[A[i]])%MOD;
	return S[n] = (ans + MOD)%MOD;
}

int main(){
	forn(i, MAXC + 1){
		C[i][0] = C[i][i] = 1;
		forr(k, 1, i) C[i][k] = (C[i-1][k] + C[i-1][k-1]) % MOD;
	}
	while(cin >> q){
		forn(cs, q){
			scanf("%d %d", &n, &f);
			hallar_div(n, D);
			forn(i, D.size())solve(D[i], f);
			printf("%lld\n", S[n]);
		}
	}
}


#include <bits/stdc++.h>
using namespace std;
#define forr(i, a, b) for(int i = (int) a; i < (int) b; i++)
#define forn(i, n) forr(i, 0, n)
#define pb push_back
typedef long long ll;
const int MAXN = 100500, MOD = 1e9+7;

void hallar_div(int n, vector<int> &X){
	X.clear(); int p;
	for(p = 1; p*p < n; p++)if(!(n%p))X.pb(p), X.pb(n/p);
	if(p*p == n)X.pb(p);
	sort(X.begin(), X.end());
}

int n, f, q;
ll S[MAXN];
vector<int> D;

ll expmod(ll b, ll e){
    if(!e) return 1;
    return (e%2 ? b : 1) * expmod(b*b%MOD, e/2) %MOD;
}
ll F[MAXN], FI[MAXN];
ll CMB(ll n, ll k){
    if(k < 0)return 0;
    if(k > n)return 0;
    return (F[n] * FI[k] % MOD) * FI[n-k] % MOD;
}

void solve(int n, int k){
	ll ans = CMB(n-1, k-1);
	vector<int> A; hallar_div(n, A); A.pop_back();
	forn(i, A.size()) ans = (ans - S[A[i]])%MOD;
	S[n] = (ans + MOD)%MOD;
	//printf("La solucion para %d es %lld\n", n, S[n]);
}

int main(){
	F[0] = FI[0] = 1;
	forr(i, 1, MAXN)F[i] = F[i-1] * i % MOD;
	forr(i, 1, MAXN)FI[i] = FI[i-1] * expmod(i, MOD-2) % MOD;
	//cout << "Que le pasa a mi camion" << endl;
	while(cin >> q){
		forn(cs, q){
			scanf("%d %d", &n, &f);
			//cout << "Leimos bien." << endl;
			hallar_div(n, D);
			//printf("Los divisores de n son:"); forn(i, D.size())printf(" %d", D[i]); puts("");
			forn(i, D.size())solve(D[i], f);
			printf("%lld\n", S[n]);
		}
	}
}


#include <bits/stdc++.h>
using namespace std;
#define forr(i, a, b) for(int i = (int) a; i < (int) b; i++)
#define forn(i, n) forr(i, 0, n)
#define forall(it, v) for(auto it = v.begin(); it != v.end(); ++it)
#define pb push_back
#define ff first
#define ss second
typedef long long ll;
const int MAXN = 100500, MOD = 1e9+7;

struct{ int p, e;} Fafa[10];

ll expmod(ll b, ll e){
    if(!e) return 1;
    return (e%2 ? b : 1) * expmod(b*b%MOD, e/2) %MOD;
}
ll F[MAXN], FI[MAXN];
ll CMB(ll n, ll k){
    if(k < 0)return 0;
    if(k > n)return 0;
    return (F[n] * FI[k] % MOD) * FI[n-k] % MOD;
}

void solve(int m, int k){
	//S[m] = (S[m] + CMB(m-1, k-1)) %MOD;
	//for(int i = 2; i*m <= n; i++)S[i*m] = (S[i*m] - S[m] + MOD) %MOD;
}

int n, k, q;
map<int, int> P;
#define mete(x, P) if(!P.count(x)) P[x]=1; else P[x]++;

int main(){
	F[0] = FI[0] = 1;
	forr(i, 1, MAXN)F[i] = F[i-1] * i % MOD;
	forr(i, 1, MAXN)FI[i] = FI[i-1] * expmod(i, MOD-2) % MOD;
	int q; cin >> q;
    forn(cs, q){
        P.clear();
        scanf("%d %d", &n, &k);
        int p = 2; while(p*p <= n){
            if(n%p)p++;
            else {
                mete(p, P); n /= p;
            }
        }
        if(n > 1) mete(n, P);
        //printf("La factorizacion de n es:\n"); forall(it, P)printf("   %d %d\n", (it -> ff), (it -> ss)); puts("");
        int B = P.size(); int x = 0;
        forall(it, P){ Fafa[x].p = (it -> ff); Fafa[x++].e = (it -> ss); }
        ll ans = 0;
        forn(v, 1 << B){
            ll fact = 1;
            forn(i, B)fact *= ((v & (1 << i)) ? expmod(Fafa[i].p, Fafa[i].e) : -expmod(Fafa[i].p, Fafa[i].e-1));
            //printf("Sumaremos %lld\n", fact);
            if(fact >= 0)ans = (ans + CMB(fact-1, k-1))%MOD;
            else ans = (ans - CMB(-fact-1, k-1)) %MOD;
        }
        printf("%lld\n", (ans + MOD) %MOD);
    }
}


#include <bits/stdc++.h>
using namespace std;
#define forr(i, a, b) for(int i = (int) a; i < (int) b; i++)
#define forn(i, n) forr(i, 0, n)
#define forall(it, v) for(auto it = v.begin(); it != v.end(); ++it)
#define pb push_back
#define ff first
#define ss second
typedef long long ll;
const int MAXN = 100500, MOD = 1e9+7;

struct{ int p, e;} Fafa[10];

ll expmod(ll b, ll e){
    if(!e) return 1;
    return (e%2 ? b : 1) * expmod(b*b%MOD, e/2) %MOD;
}
ll F[MAXN], FI[MAXN];
ll CMB(ll n, ll k){
    if(k < 0)return 0;
    if(k > n)return 0;
    return (F[n] * FI[k] % MOD) * FI[n-k] % MOD;
}

void solve(int m, int k){
	//S[m] = (S[m] + CMB(m-1, k-1)) %MOD;
	//for(int i = 2; i*m <= n; i++)S[i*m] = (S[i*m] - S[m] + MOD) %MOD;
}

int n, k, q;
map<int, int> P;
#define mete(x, P) if(!P.count(x)) P[x]=1; else P[x]++;

int main(){
	F[0] = FI[0] = 1;
	forr(i, 1, MAXN)F[i] = F[i-1] * i % MOD;
	forr(i, 1, MAXN)FI[i] = FI[i-1] * expmod(i, MOD-2) % MOD;
	int q; cin >> q;
    forn(cs, q){
        P.clear();
        scanf("%d %d", &n, &k);
        int p = 2; while(p*p <= n){
            if(n%p)p++;
            else {
                mete(p, P); n /= p;
            }
        }
        if(n > 1) mete(n, P);
        //printf("La factorizacion de n es:\n"); forall(it, P)printf("   %d %d\n", (it -> ff), (it -> ss)); puts("");
        int B = P.size(); int x = 0;
        forall(it, P){ Fafa[x].p = (it -> ff); Fafa[x++].e = (it -> ss); }
        ll ans = 0;
        forn(v, 1 << B){
            ll fact = 1;
            forn(i, B)fact *= ((v & (1 << i)) ? expmod(Fafa[i].p, Fafa[i].e) : -expmod(Fafa[i].p, Fafa[i].e-1));
            //printf("Sumaremos %lld\n", fact);
            if(fact >= 0)ans += CMB(fact-1, k-1);
            else ans -= CMB(-fact-1, k-1);
        }
        printf("%lld\n", ans);
    }
}


#include <bits/stdc++.h>
using namespace std;
#define forr(i, a, b) for(int i = (int) a; i < (int) b; i++)
#define forn(i, n) forr(i, 0, n)
#define pb push_back
typedef long long ll;
const int MAXN = 100500, MOD = 1e9+7;

void hallar_div(int n, vector<int> &X){
	X.clear(); int p;
	for(p = 1; p*p < n; p++)if(!(n%p))X.pb(p), X.pb(n/p);
	if(p*p == n)X.pb(p);
	sort(X.begin(), X.end());
}

int n, f, q;
ll S[MAXN];
vector<int> D;

ll expmod(ll b, ll e){
    if(!e) return 1;
    return (e%2 ? b : 1) * expmod(b*b%MOD, e/2) %MOD;
}
ll F[MAXN], FI[MAXN];
ll CMB(ll n, ll k){
    if(k < 0)return 0;
    if(k > n)return 0;
    return (F[n] * FI[k] % MOD) * FI[n-k] % MOD;
}

void solve(int n, int k){
	ll ans = CMB(n-1, k-1);
	vector<int> A;
	for(int i = 0; D[i] < n; i++){
        if(!(n%D[i]))A.pb(D[i]);
	}
	forn(i, A.size()) ans = (ans - S[A[i]])%MOD;
	S[n] = (ans + MOD)%MOD;
	//printf("La solucion para %d es %lld\n", n, S[n]);
}

int main(){
	F[0] = FI[0] = 1;
	forr(i, 1, MAXN)F[i] = F[i-1] * i % MOD;
	forr(i, 1, MAXN)FI[i] = FI[i-1] * expmod(i, MOD-2) % MOD;
	//cout << "Que le pasa a mi camion" << endl;
	while(cin >> q){
		forn(cs, q){
			scanf("%d %d", &n, &f);
			//cout << "Leimos bien." << endl;
			hallar_div(n, D);
			//printf("Los divisores de n son:"); forn(i, D.size())printf(" %d", D[i]); puts("");
			forn(i, D.size())solve(D[i], f);
			printf("%lld\n", S[n]);
		}
	}
}


#include<bits/stdc++.h>

using namespace std;

#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define forn(i, n) fore(i, 0, n)

#define all(a) (a).begin(), (a).end()
#define sz(a) int((a).size())
#define sqr(a) ((a) * (a))

#define mp make_pair
#define pb push_back

#define x first
#define y second

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

const int INF = int(1e9);
const li INF64 = li(1e18);
const ld EPS = 1e-9;

const int MOD = int(1e9) + 7;

inline int norm(int a) {
    while(a >= MOD)
        a -= MOD;
    while(a < 0)
        a -= MOD;
    return a;
}

inline int mul(int a, int b) {
    return int(a * 1ll * b % MOD);
}

inline int binPow(int a, int k) {
    int ans = 1;
    while(k > 0) {
        if(k & 1) ans = mul(ans, a);
        a = mul(a, a);
        k >>= 1;
    }
    return ans;
}

const int N = 100 * 1000 + 555;
int q;
pt qs[N];

inline bool read() {
    if(!(cin >> q))
        return false;
    forn(i, q)
        assert(scanf("%d%d", &qs[i].x, &qs[i].y) == 2);
    return true;
}

int f[N], inf[N];

vector<int> ps[N];
bool npr[N];

void precalc() {
    f[0] = inf[0] = 1;
    fore(i, 1, N) {
        f[i] = mul(f[i - 1], i);
        inf[i] = binPow(f[i], MOD - 2);
    }

    npr[0] = npr[1] = 1;
    forn(i, N) {
        if(npr[i])
            continue;
        for(int j = i; j < N; j += i) {
            npr[j] = 1;
            ps[j].pb(i);
        }
    }
}

inline int c(int n, int k) {
    if(k < 0 || n < k)
        return 0;
    return mul(f[n], mul(inf[k], inf[n - k]));
}

inline void solve() {
    forn(_i, q) {
        int n = qs[_i].x, k = qs[_i].y;
        int ans = 0;
        int sign[2] = {+1, -1};
        forn(msk, 1 << sz(ps[n])) {
            int val = n, cnt = 0;
            forn(i, sz(ps[n])) {
                if((msk >> i) & 1)
                    val /= ps[n][i], cnt++;
            }
            ans = norm(ans + sign[cnt & 1] * c(val - 1, k - 1));
        }

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

int main() {
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    int tt = clock();
#endif
    cout << fixed << setprecision(15);
    precalc();

    if(read()) {
        solve();

#ifdef _DEBUG
        cerr << "TIME = " << ld(clock() - tt) / CLOCKS_PER_SEC << endl;
        tt = clock();
#endif
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define forn(i, n) fore(i, 0, n)

#define all(a) (a).begin(), (a).end()
#define sz(a) int((a).size())
#define sqr(a) ((a) * (a))

#define mp make_pair
#define pb push_back

#define x first
#define y second

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

const int INF = int(1e9);
const li INF64 = li(1e18);
const ld EPS = 1e-9;

const int MOD = int(1e9) + 7;

inline int norm(int a) {
    while(a >= MOD)
        a -= MOD;
    while(a < 0)
        a += MOD;
    return a;
}

inline int mul(int a, int b) {
    return int(a * 1ll * b % MOD);
}

inline int binPow(int a, int k) {
    int ans = 1;
    while(k > 0) {
        if(k & 1) ans = mul(ans, a);
        a = mul(a, a);
        k >>= 1;
    }
    return ans;
}

const int N = 100 * 1000 + 555;
int q;
pt qs[N];

bool gen() {
    q = 100 * 1000;
    forn(i, q)
        qs[i] = {30030, 1 + rand() % 30030};
    return true;
}

inline bool read() {
//    return gen();

    if(!(cin >> q))
        return false;
    forn(i, q)
        assert(scanf("%d%d", &qs[i].x, &qs[i].y) == 2);
    return true;
}

int f[N], inf[N];

vector<int> ps[N];
bool npr[N];

void precalc() {
    f[0] = inf[0] = 1;
    fore(i, 1, N) {
        f[i] = mul(f[i - 1], i);
        inf[i] = binPow(f[i], MOD - 2);
    }

    npr[0] = npr[1] = 1;
    forn(i, N) {
        if(npr[i])
            continue;
        for(int j = i; j < N; j += i) {
            npr[j] = 1;
            ps[j].pb(i);
        }
    }
}

inline int c(int n, int k) {
    if(k < 0 || n < k)
        return 0;
    return mul(f[n], mul(inf[k], inf[n - k]));
}

inline void solve() {
    forn(_i, q) {
        int n = qs[_i].x, k = qs[_i].y;
        int ans = 0;
        int sign[2] = {+1, -1};
        forn(msk, 1 << sz(ps[n])) {
            int val = n, cnt = 0;
            forn(i, sz(ps[n])) {
                if((msk >> i) & 1)
                    val /= ps[n][i], cnt++;
            }
            ans = norm(ans + sign[cnt & 1] * c(val - 1, k - 1));
        }

//        if((_i & ((1 << 16) - 1)) == 0)
            printf("%d\n", ans);
    }
}

int main() {
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    int tt = clock();
#endif
    cout << fixed << setprecision(15);
    precalc();

    if(read()) {
        solve();

#ifdef _DEBUG
        cerr << "TIME = " << ld(clock() - tt) / CLOCKS_PER_SEC << endl;
        tt = clock();
#endif
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define forn(i, n) fore(i, 0, n)

#define all(a) (a).begin(), (a).end()
#define sz(a) int((a).size())
#define sqr(a) ((a) * (a))

#define mp make_pair
#define pb push_back

#define x first
#define y second

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

const int INF = int(1e9);
const li INF64 = li(1e18);
const ld EPS = 1e-9;

const int MOD = int(1e9) + 7;

inline int norm(int a) {
    while(a >= MOD)
        a -= MOD;
    while(a < 0)
        a -= MOD;
    return a;
}

inline int mul(int a, int b) {
    return int(a * 1ll * b % MOD);
}

inline int binPow(int a, int k) {
    int ans = 1;
    while(k > 0) {
        if(k & 1) ans = mul(ans, a);
        a = mul(a, a);
        k >>= 1;
    }
    return ans;
}

const int N = 100 * 1000 + 555;
int q;
pt qs[N];

inline bool read() {
    if(!(cin >> q))
        return false;
    forn(i, q)
        assert(scanf("%d%d", &qs[i].x, &qs[i].y) == 2);
    return true;
}

int f[N], inf[N];

vector<int> ps[N];
bool npr[N];

void precalc() {
    f[0] = inf[0] = 1;
    fore(i, 1, N) {
        f[i] = mul(f[i - 1], i);
        inf[i] = binPow(f[i], MOD - 2);
    }

    npr[0] = npr[1] = 1;
    forn(i, N) {
        if(npr[i])
            continue;
        for(int j = 2 * i; j < N; j += i) {
            npr[j] = 1;
            ps[j].pb(i);
        }
    }
}

inline int c(int n, int k) {
    if(k < 0 || n < k)
        return 0;
    return mul(f[n], mul(inf[k], inf[n - k]));
}

inline void solve() {
    forn(_i, q) {
        int n = qs[_i].x, k = qs[_i].y;
        int ans = 0;
        int sign[2] = {+1, -1};
        forn(msk, 1 << sz(ps[n])) {
            int val = n, cnt = 0;
            forn(i, sz(ps[n])) {
                if((msk >> i) & 1)
                    val /= ps[n][i], cnt++;
            }
            ans = norm(ans + sign[cnt & 1] * c(val - 1, k - 1));
        }

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

int main() {
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    int tt = clock();
#endif
    cout << fixed << setprecision(15);
    precalc();

    if(read()) {
        solve();

#ifdef _DEBUG
        cerr << "TIME = " << ld(clock() - tt) / CLOCKS_PER_SEC << endl;
        tt = clock();
#endif
    }
    return 0;
}


/*  "Sahand Alitanloo"  */
#include <bits/stdc++.h>
#define F first
#define S second
#define fast() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define per(i) cout<<fixed<<setprecision(i)
#define pb push_back
#define all(v) begin(v),end(v)
using namespace std;
typedef pair<int,int> pii;
typedef long double ld;
typedef long long ll;
const int MAX_N = 1e5+10;
const ll mod = 1e9+7;
inline ll bpow(ll t,ll n){ll ans=1;while(n>0){if(n&1)ans=(ans*t)%mod;t=(t*t)%mod,n>>=1;}return ans;}

int g[MAX_N],nopf[MAX_N];
vector<int> primes;
ll fact[MAX_N];
ll c(ll n,ll k){
    if(k>n||k<0)
        return 0;
    return (fact[n]*bpow((fact[n-k]*fact[k])%mod,mod-2))%mod;
}
void get_fact(){
    fact[0]=1;
    for(ll i=1;i<MAX_N;i++)
        fact[i]=(fact[i-1]*i)%mod;
}
void get_g(){
    for(int i=2;i<MAX_N;i++)
        if(nopf[i]==0){
            if(i*i<MAX_N)
                primes.pb(i);
            for(int j=i;j<MAX_N;j+=i)
                nopf[j]++;
        }
    for(int i=1;i<MAX_N;i++){
        bool ok=false;
        for(int j:primes)
            if(i%(j*j)==0){
                ok=true;
                break;
            }
        if(ok)
            g[i]=0;
        else{
            int num=nopf[i];
            if(num%2==0)
                g[i]=1;
            else
                g[i]=-1;
        }
    }
}
ll num(int n,int k){
    return c(n-1,k-1);
}
main(){
    fast();per(0);
    get_fact();
    get_g();
    int t;cin>>t;
    while(t--){
        int n,f;cin>>n>>f;
        ll ans=0;
        vector<int> divs;
        for(int d=1;d*d<=n;d++)
            if(n%d==0){
                if(n/d==d)
                    divs.pb(d);
                else{
                    divs.pb(d);
                    divs.pb(n/d);
                }
            }
        for(int d:divs){
            ans+=g[d]*num(n/d,f),ans=(ans+mod)%mod;
            //cout<<g[d]<<" "<<c(n/d,f)<<endl;
        }
        cout<<(ans+mod)%mod<<endl;
    }
}


/*  "Sahand Alitanloo"  */
#include <bits/stdc++.h>
#define F first
#define S second
#define fast() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define per(i) cout<<fixed<<setprecision(i)
#define pb push_back
#define all(v) begin(v),end(v)
using namespace std;
typedef pair<int,int> pii;
typedef long double ld;
typedef long long ll;
const int MAX_N = 1e2+10;
const ll mod = 1e9+7;
inline ll bpow(ll t,ll n){ll ans=1;while(n>0){if(n&1)ans=(ans*t)%mod;t=(t*t)%mod,n>>=1;}return ans;}

int g[MAX_N],nopf[MAX_N];
vector<int> primes;
ll fact[MAX_N];
ll ifact[MAX_N];
ll c(ll n,ll k){
    if(k>n||k<0)
        return 0;
    return (fact[n]*((ifact[n-k]*ifact[k])%mod))%mod;
}
void get_fact(){
    fact[0]=1;
    ifact[0]=1;
    for(ll i=1;i<MAX_N;i++)
        fact[i]=(fact[i-1]*i)%mod,ifact[i]=bpow(fact[i],mod-2);
}
void get_g(){
    for(int i=2;i<MAX_N;i++)
        if(nopf[i]==0){
            if(i*i<MAX_N)
                primes.pb(i);
            for(int j=i;j<MAX_N;j+=i)
                nopf[j]++;
        }
    for(int i=1;i<MAX_N;i++){
        bool ok=false;
        for(int j:primes)
            if(i%(j*j)==0){
                ok=true;
                break;
            }
        if(ok)
            g[i]=0;
        else{
            int num=nopf[i];
            if(num%2==0)
                g[i]=1;
            else
                g[i]=-1;
        }
    }
}
ll num(int n,int k){
    return c(n-1,k-1);
}
main(){
    fast();per(0);
    get_fact();
    get_g();
    int t;cin>>t;
    while(t--){
        int n,f;cin>>n>>f;
        ll ans=0;
        for(int d=1;d*d<=n;d++)
            if(n%d==0){
                if(n/d==d)
                    ans+=g[d]*num(n/d,f),ans=(ans+mod)%mod;
                else{
                    ans+=g[d]*num(n/d,f),ans=(ans+mod)%mod;
                    ans+=g[n/d]*num(d,f),ans=(ans+mod)%mod;
                }
            }
        cout<<(ans+mod)%mod<<'\n';
    }
}


/*  "Sahand Alitanloo"  */
#include <bits/stdc++.h>
#define F first
#define S second
#define fast() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define per(i) cout<<fixed<<setprecision(i)
#define pb push_back
#define all(v) begin(v),end(v)
using namespace std;
typedef pair<int,int> pii;
typedef long double ld;
typedef long long ll;
const int MAX_N = 1e5+10;
const ll mod = 1e9+7;
inline ll bpow(ll t,ll n){ll ans=1;while(n>0){if(n&1)ans=(ans*t)%mod;t=(t*t)%mod,n>>=1;}return ans;}

int g[MAX_N],nopf[MAX_N];
vector<int> primes;
ll fact[MAX_N];
ll c(ll n,ll k){
    if(k>n||k<0)
        return 0;
    return (fact[n]*bpow((fact[n-k]*fact[k])%mod,mod-2))%mod;
}
void get_fact(){
    fact[0]=1;
    for(ll i=1;i<MAX_N;i++)
        fact[i]=(fact[i-1]*i)%mod;
}
void get_g(){
    for(int i=2;i*i<MAX_N;i++)
        if(nopf[i]==0){
            if(i*i<MAX_N)
                primes.pb(i);
            for(int j=i;j<MAX_N;j+=i)
                nopf[j]++;
        }
    for(int i=1;i<MAX_N;i++){
        bool ok=false;
        for(int j:primes)
            if(i%(j*j)==0){
                ok=true;
                break;
            }
        if(ok)
            g[i]=0;
        else{
            int num=nopf[i];
            if(num%2==0)
                g[i]=1;
            else
                g[i]=-1;
        }
    }
}
ll num(int n,int k){
    return c(n-1,k-1);
}
main(){
    fast();per(0);
    get_fact();
    get_g();
    int t;cin>>t;
    while(t--){
        int n,f;cin>>n>>f;
        ll ans=0;
        vector<int> divs;
        for(int d=1;d*d<=n;d++)
            if(n%d==0){
                if(n/d==d)
                    divs.pb(d);
                else{
                    divs.pb(d);
                    divs.pb(n/d);
                }
            }
        for(int d:divs){
            ans+=g[d]*num(n/d,f),ans=(ans+mod)%mod;
            //cout<<g[d]<<" "<<c(n/d,f)<<endl;
        }
        cout<<(ans+mod)%mod<<endl;
    }
}


/*  "Sahand Alitanloo"  */
#include <bits/stdc++.h>
#define F first
#define S second
#define fast() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define per(i) cout<<fixed<<setprecision(i)
#define pb push_back
#define all(v) begin(v),end(v)
using namespace std;
typedef pair<int,int> pii;
typedef long double ld;
typedef long long ll;
const int MAX_N = 1e5+10;
const ll mod = 1e9+7;
inline ll bpow(ll t,ll n){ll ans=1;while(n>0){if(n&1)ans=(ans*t)%mod;t=(t*t)%mod,n>>=1;}return ans;}

int g[MAX_N],nopf[MAX_N];
vector<int> primes;
ll fact[MAX_N];
ll c(ll n,ll k){
    if(k>n||k<0)
        return 0;
    return (fact[n]*bpow((fact[n-k]*fact[k])%mod,mod-2))%mod;
}
void get_fact(){
    fact[0]=1;
    for(ll i=1;i<MAX_N;i++)
        fact[i]=(fact[i-1]*i)%mod;
}
void get_g(){
    for(int i=2;i<MAX_N;i++)
        if(nopf[i]==0){
            if(i*i<MAX_N)
                primes.pb(i);
            for(int j=i;j<MAX_N;j+=i)
                nopf[j]++;
        }
    for(int i=1;i<MAX_N;i++){
        bool ok=false;
        for(int j:primes)
            if(i%(j*j)==0){
                ok=true;
                break;
            }
        if(ok)
            g[i]=0;
        else{
            int num=nopf[i];
            if(num%2==0)
                g[i]=1;
            else
                g[i]=-1;
        }
    }
}
ll num(int n,int k){
    return c(n-1,k-1);
}
main(){
    fast();per(0);
    get_fact();
    get_g();
    int t;cin>>t;
    while(t--){
        int n,f;cin>>n>>f;
        ll ans=0;
        for(int d=1;d*d<=n;d++)
            if(n%d==0){
                if(n/d==d)
                    ans+=g[d]*num(n/d,f),ans=(ans+mod)%mod;
                else{
                    ans+=g[d]*num(n/d,f),ans=(ans+mod)%mod;
                    ans+=g[n/d]*num(d,f),ans=(ans+mod)%mod;
                }
            }
        cout<<(ans+mod)%mod<<'\n';
    }
}


/*  "Sahand Alitanloo"  */
#include <bits/stdc++.h>
#define F first
#define S second
#define fast() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define per(i) cout<<fixed<<setprecision(i)
#define pb push_back
#define all(v) begin(v),end(v)
using namespace std;
typedef pair<int,int> pii;
typedef long double ld;
typedef long long ll;
const int MAX_N = 1e5+10;
const ll mod = 1e9+7;
inline ll bpow(ll t,ll n){ll ans=1;while(n>0){if(n&1)ans=(ans*t)%mod;t=(t*t)%mod,n>>=1;}return ans;}

ll g[MAX_N],nopf[MAX_N];
vector<ll> primes;
ll fact[MAX_N];
ll ifact[MAX_N];
ll c(ll n,ll k){
    if(k>n||k<0)
        return 0;
    return (fact[n]*((ifact[n-k]*ifact[k])%mod))%mod;
}
void get_fact(){
    fact[0]=1;
    ifact[0]=1;
    for(ll i=1;i<MAX_N;i++)
        fact[i]=(fact[i-1]*i)%mod,ifact[i]=bpow(fact[i],mod-2)%mod;
}
void get_g(){
    for(int i=2;i<MAX_N;i++)
        if(nopf[i]==0){
            if(i*i<MAX_N)
                primes.pb(i);
            for(int j=i;j<MAX_N;j+=i)
                nopf[j]++;
        }
    for(int i=1;i<MAX_N;i++){
        bool ok=false;
        for(int j:primes)
            if(i%(j*j)==0){
                ok=true;
                break;
            }
        if(ok)
            g[i]=0;
        else{
            int num=nopf[i];
            if(num%2==0)
                g[i]=1;
            else
                g[i]=-1;
        }
    }
}
ll num(int n,int k){
    return c(n-1,k-1);
}
main(){
    fast();per(0);
    get_fact();
    get_g();
    int t;cin>>t;
    while(t--){
        int n,f;cin>>n>>f;
        ll ans=0;
        for(ll d=1;d*d<=n;d++)
            if(n%d==0){
                if(n/d==d)
                    ans+=g[d]*num(n/d,f),ans=(ans+mod)%mod;
                else{
                    ans+=g[d]*num(n/d,f),ans=(ans+mod)%mod;
                    ans+=g[n/d]*num(d,f),ans=(ans+mod)%mod;
                }
            }
        cout<<(ans+mod)%mod<<'\n';
    }
}


/*  "Sahand Alitanloo"  */
#include <bits/stdc++.h>
#define F first
#define S second
#define fast() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define per(i) cout<<fixed<<setprecision(i)
#define pb push_back
#define all(v) begin(v),end(v)
using namespace std;
typedef pair<int,int> pii;
typedef long double ld;
typedef long long ll;
const int MAX_N = 1e5+10;
const ll mod = 1e9+7;
inline ll bpow(ll t,ll n){ll ans=1;while(n>0){if(n&1)ans=(ans*t)%mod;t=(t*t)%mod,n>>=1;}return ans;}

int g[MAX_N],nopf[MAX_N];
vector<int> primes;
ll fact[MAX_N];
ll c(ll n,ll k){
    if(k>n||k<0)
        return 0;
    return (fact[n]*bpow((fact[n-k]*fact[k])%mod,mod-2))%mod;
}
void get_fact(){
    fact[0]=1;
    for(ll i=1;i<MAX_N;i++)
        fact[i]=(fact[i-1]*i)%mod;
}
void get_g(){
    for(int i=2;i*i<MAX_N;i++)
        if(nopf[i]==0){
            if(i*i<MAX_N)
                primes.pb(i);
            for(int j=i*i;j<MAX_N;j+=i)
                nopf[j]++;
        }
    for(int i=1;i<MAX_N;i++){
        bool ok=false;
        for(int j:primes)
            if(i%(j*j)==0){
                ok=true;
                break;
            }
        if(ok)
            g[i]=0;
        else{
            int num=nopf[i];
            if(num%2==0)
                g[i]=1;
            else
                g[i]=-1;
        }
    }
}
ll num(int n,int k){
    return c(n-1,k-1);
}
main(){
    fast();per(0);
    get_fact();
    get_g();
    int t;cin>>t;
    while(t--){
        int n,f;cin>>n>>f;
        ll ans=0;
        vector<int> divs;
        for(int d=1;d*d<=n;d++)
            if(n%d==0){
                if(n/d==d)
                    divs.pb(d);
                else{
                    divs.pb(d);
                    divs.pb(n/d);
                }
            }
        for(int d:divs){
            ans+=g[d]*num(n/d,f),ans=(ans+mod)%mod;
            //cout<<g[d]<<" "<<c(n/d,f)<<endl;
        }
        cout<<(ans+mod)%mod<<endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

int fact[100010], bfact[100010];
const int md = 1000000007;

int C(int n, int k){
    if(k > n) return 0;
    int result = fact[n];
    result = (result * 1ll * bfact[k]) % md;
    result = (result * 1ll * bfact[n-k]) % md;
    return result;
}

int binpow(int n, int k){
    if(k == 0) return 1;
    if(k & 1) return (binpow(n, k - 1) * 1ll * n) % md;
    int t = binpow(n, k >> 1);
    return (t * 1ll * t) % md;
}

int modAdd(int x){
    if(x >= md) x -= md;
    if(x < 0) x += md;
    return x;
}

vector < int > g[100010];
unordered_map < int, int > d[100010];

int go(int n, int f){
    if(!d[n].count(f)){
        int res = C(n - 1, f - 1);
        for(int u : g[n]){
            if(u != n) res = modAdd(res - C(u - 1, f - 1));
        }
        d[n][f] = res;
    }
    return d[n][f];
}

int main()
{
    for(int i = 1; i <= 100000; i++){
        for(int j = i; j <= 100000; j += i){
            g[j].push_back(i);
        }
    }
    fact[0] = bfact[0] = 1;
    for(int i = 1; i <= 100000; i++){
        fact[i] = (fact[i-1] * 1ll * i) % md;
        bfact[i] = binpow(fact[i], md - 2);
    }
    int t;
    scanf("%d", &t);
    while(t--){
        int n, f;
        scanf("%d %d", &n, &f);
        if(f == 1){
            if(n == 1) puts("1");
            else puts("0");
            continue;
        }
        int an = go(n, f);
        printf("%d\n", an);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int fact[100010], bfact[100010];
const int md = 1000000007;

int C(int n, int k){
    if(k > n) return 0;
    int result = fact[n];
    result = (result * 1ll * bfact[k]) % md;
    result = (result * 1ll * bfact[n-k]) % md;
    return result;
}

int binpow(int n, int k){
    if(k == 0) return 1;
    if(k & 1) return (binpow(n, k - 1) * 1ll * n) % md;
    int t = binpow(n, k >> 1);
    return (t * 1ll * t) % md;
}

int modAdd(int x){
    if(x >= md) x -= md;
    if(x < 0) x += md;
    return x;
}

vector < int > g[100010];
unordered_map < int, int > d[100010];

int go(int n, int f){
    if(!d[n].count(f)){
        if(n >= f){
            int res = C(n - 1, f - 1);
            for(int u : g[n]){
                if(u != n && u >= f) res = modAdd(res - go(u, f));
            }
            d[n][f] = res;
        }
    }
    return d[n][f];
}

int main()
{
    for(int i = 1; i <= 100000; i++){
        for(int j = i; j <= 100000; j += i){
            g[j].push_back(i);
        }
    }
    fact[0] = bfact[0] = 1;
    for(int i = 1; i <= 100000; i++){
        fact[i] = (fact[i-1] * 1ll * i) % md;
        bfact[i] = binpow(fact[i], md - 2);
    }
    int t;
    scanf("%d", &t);
    while(t--){
        int n, f;
        scanf("%d %d", &n, &f);
        if(f == 1){
            if(n == 1) puts("1");
            else puts("0");
            continue;
        }
        int an = go(n, f);
        printf("%d\n", an);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int fact[100010], bfact[100010];
const int md = 1000000007;

int C(int n, int k){
    if(k > n) return 0;
    int result = fact[n];
    result = (result * 1ll * bfact[k]) % md;
    result = (result * 1ll * bfact[n-k]) % md;
    return result;
}

int binpow(int n, int k){
    if(k == 0) return 1;
    if(k & 1) return (binpow(n, k - 1) * 1ll * n) % md;
    int t = binpow(n, k >> 1);
    return (t * 1ll * t) % md;
}

int modAdd(int x){
    if(x >= md) x -= md;
    if(x < 0) x += md;
    return x;
}

vector < int > g[100010];

int main()
{
    for(int i = 1; i <= 100000; i++){
        for(int j = i; j <= 100000; j += i){
            g[j].push_back(i);
        }
    }
    fact[0] = bfact[0] = 1;
    for(int i = 1; i <= 100000; i++){
        fact[i] = (fact[i-1] * 1ll * i) % md;
        bfact[i] = binpow(fact[i], md - 2);
    }
    int t;
    scanf("%d", &t);
    while(t--){
        int n, f;
        scanf("%d %d", &n, &f);
        if(f == 1){
            if(n == 1) puts("1");
            else puts("0");
            continue;
        }
        int an = C(n - 1, f - 1);
        for(int u : g[n]){
            if(u != n) an = modAdd(an - C(u - 1, f - 1));
        }
        printf("%d\n", an);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int fact[100010], bfact[100010];
const int md = 1000000007;

int C(int n, int k){
    if(k > n) return 0;
    int result = fact[n];
    result = (result * 1ll * bfact[k]) % md;
    result = (result * 1ll * bfact[n-k]) % md;
    return result;
}

int binpow(int n, int k){
    if(k == 0) return 1;
    if(k & 1) return (binpow(n, k - 1) * 1ll * n) % md;
    int t = binpow(n, k >> 1);
    return (t * 1ll * t) % md;
}

int modAdd(int x){
    if(x >= md) x -= md;
    if(x < 0) x += md;
    return x;
}

vector < int > g[100010];
unordered_map < int, int > d[100010];

int go(int n, int f){
    if(!d[n].count(f)){
        int res = C(n - 1, f - 1);
        for(int u : g[n]){
            if(u != n) res = modAdd(res - go(u, f));
        }
        d[n][f] = res;
    }
    return d[n][f];
}

int main()
{
    for(int i = 1; i <= 100000; i++){
        for(int j = i; j <= 100000; j += i){
            g[j].push_back(i);
        }
    }
    fact[0] = bfact[0] = 1;
    for(int i = 1; i <= 100000; i++){
        fact[i] = (fact[i-1] * 1ll * i) % md;
        bfact[i] = binpow(fact[i], md - 2);
    }
    int t;
    scanf("%d", &t);
    while(t--){
        int n, f;
        scanf("%d %d", &n, &f);
        if(f == 1){
            if(n == 1) puts("1");
            else puts("0");
            continue;
        }
        int an = go(n, f);
        printf("%d\n", an);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int fact[100010], bfact[100010];
const int md = 1000000007;

int C(int n, int k){
    if(k > n) return 0;
    int result = fact[n];
    result = (result * 1ll * bfact[k]) % md;
    result = (result * 1ll * bfact[n-k]) % md;
    return result;
}

int binpow(int n, int k){
    if(k == 0) return 1;
    if(k & 1) return (binpow(n, k - 1) * 1ll * n) % md;
    int t = binpow(n, k >> 1);
    return (t * 1ll * t) % md;
}

int modAdd(int x){
    if(x >= md) x -= md;
    if(x < 0) x += md;
    return x;
}

vector < int > g[100010];

int main()
{
    for(int i = 1; i <= 100000; i++){
        for(int j = i; j <= 100000; j += i){
            g[j].push_back(i);
        }
    }
    fact[0] = bfact[0] = 1;
    for(int i = 1; i <= 100000; i++){
        fact[i] = (fact[i-1] * 1ll * i) % md;
        bfact[i] = binpow(fact[i], md - 2);
    }
    int t;
    scanf("%d", &t);
    while(t--){
        int n, f;
        scanf("%d %d", &n, &f);
        int an = C(n - 1, f - 1);
        for(int u : g[n]){
            if(u != n) an = modAdd(an - C(u - 1, f - 1));
        }
        printf("%d\n", an);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int maxn = 2e5 + 10, mod = 1e9 + 7;
int f[maxn], invf[maxn];
bool v[maxn], p[maxn];
vector<int> pr;

inline int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; }
inline int sub(int a, int b) { return a - b < 0 ? a - b + mod : a - b; }
inline int mul(int a, int b) { return a * 1ll * b % mod; }

void sieve() {
    for (int i = 2; i < maxn; ++i) {
        if (!v[i]) pr.push_back(i), p[i] = true;
        for (int j = 0; i * pr[j] < maxn; ++j) {
            v[i * pr[j]] = true;
            if (i % pr[j] == 0) break;
        }
    }
}

int fpow(int a, int n) {
    int ret = 1;
    for (; n; n >>= 1) {
        if (n & 1) ret = mul(ret, a);
        a = mul(a, a);
    }
    return ret;
}

void init() {
    f[0] = 1; invf[0] = 1;
    for (int i = 1; i < maxn; ++i) {
        f[i] = mul(f[i - 1], i);
        invf[i] = fpow(f[i], mod - 2);
    }
}

inline int c(int n, int k) { return n < k || n < 0 || k < 0 ? 0 : mul(f[n], mul(invf[k], invf[n - k])); }
inline int h(int n, int k) { return c(n + k - 1, k); }

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    sieve(); init();
    int q; cin >> q; while (q--) {
        int n, f; cin >> n >> f;
        int tn = n, ans = h(f, n - f);
        size_t ptr = 0;
        vector<int> di;
        while (tn > 1) {
            if (tn % pr[ptr] == 0) di.push_back(pr[ptr]);
            while (tn % pr[ptr] == 0) tn /= pr[ptr];
            ++ptr;
        }
        int sz = di.size();
        for (int m = 1; m < (1 << sz); ++m) {
            int d = 1;
            for (size_t i = 0; i < di.size(); ++i) {
                if ((1 << i) & m) d *= di[i];
            }
            int c = h(f, n / d - f);
            if (__builtin_popcount(m) & 1) ans = sub(ans, c);
            else ans = add(ans, c);
        }
        cout << ans << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int maxn = 2e5 + 10, mod = 1e9 + 7;
int f[maxn], invf[maxn];
bool v[maxn], p[maxn];
vector<int> pr;

inline int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; }
inline int sub(int a, int b) { return a - b < 0 ? a - b + mod : a - b; }
inline int mul(int a, int b) { return a * 1ll * b % mod; }

void sieve() {
    for (int i = 2; i < maxn; ++i) {
        if (!v[i]) pr.push_back(i), p[i] = true;
        for (int j = 0; i * pr[j] < maxn; ++j) {
            v[i * pr[j]] = true;
            if (i % pr[j] == 0) break;
        }
    }
}

int fpow(int a, int n) {
    int ret = 1;
    for (; n; n >>= 1) {
        if (n & 1) ret = mul(ret, a);
        a = mul(a, a);
    }
    return ret;
}

void init() {
    f[0] = 1; invf[0] = 1;
    for (int i = 1; i < maxn; ++i) {
        f[i] = mul(f[i - 1], i);
        invf[i] = fpow(f[i], mod - 2);
    }
}

inline int c(int n, int k) { return n < k ? 0 : mul(f[n], mul(invf[k], invf[n - k])); }
inline int h(int n, int k) { return c(n + k - 1, k); }

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    sieve(); init();
    int q; cin >> q; while (q--) {
        int n, f; cin >> n >> f;
        int ans = h(f, n - f);
        if (!p[n]) for (int d : pr) if (n % d == 0) {
            int m = n / d;
            ans = sub(ans, h(f , m - f));
        }
        cout << ans << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int maxn = 2e5 + 10, mod = 1e9 + 7;
int f[maxn], invf[maxn];
bool v[maxn];
vector<int> pr;

inline int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; }
inline int sub(int a, int b) { return a - b < 0 ? a - b + mod : a - b; }
inline int mul(int a, int b) { return a * 1ll * b % mod; }

void sieve() {
    for (int i = 2; i < maxn; ++i) {
        if (!v[i]) pr.push_back(i);
        for (int j = 0; i * pr[j] < maxn; ++j) {
            v[i * pr[j]] = true;
            if (i % pr[j] == 0) break;
        }
    }
}

int fpow(int a, int n) {
    int ret = 1;
    for (; n; n >>= 1) {
        if (n & 1) ret = mul(ret, a);
        a = mul(a, a);
    }
    return ret;
}

void init() {
    f[0] = 1; invf[0] = 1;
    for (int i = 1; i < maxn; ++i) {
        f[i] = mul(f[i - 1], i);
        invf[i] = fpow(f[i], mod - 2);
    }
}

inline int c(int n, int k) { return n < k ? 0 : mul(f[n], mul(invf[k], invf[n - k])); }
inline int h(int n, int k) { return c(n + k - 1, k); }

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    sieve(); init();
    int q; cin >> q; while (q--) {
        int n, f; cin >> n >> f;
        int ans = h(f, n - f);
        if (!v[n]) for (int d : pr) if (n % d == 0) {
            int m = n / d;
            ans = sub(ans, h(f , m - f));
        }
        cout << ans << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int maxn = 2e5 + 10, mod = 1e9 + 7;
int f[maxn], invf[maxn];
bool v[maxn], p[maxn];
vector<int> pr;

inline int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; }
inline int sub(int a, int b) { return a - b < 0 ? a - b + mod : a - b; }
inline int mul(int a, int b) { return a * 1ll * b % mod; }

void sieve() {
    for (int i = 2; i < maxn; ++i) {
        if (!v[i]) pr.push_back(i), p[i] = true;
        for (int j = 0; i * pr[j] < maxn; ++j) {
            v[i * pr[j]] = true;
            if (i % pr[j] == 0) break;
        }
    }
}

int fpow(int a, int n) {
    int ret = 1;
    for (; n; n >>= 1) {
        if (n & 1) ret = mul(ret, a);
        a = mul(a, a);
    }
    return ret;
}

void init() {
    f[0] = 1; invf[0] = 1;
    for (int i = 1; i < maxn; ++i) {
        f[i] = mul(f[i - 1], i);
        invf[i] = fpow(f[i], mod - 2);
    }
}

inline int c(int n, int k) { return n < k || n < 0 || k < 0 ? 0 : mul(f[n], mul(invf[k], invf[n - k])); }
inline int h(int n, int k) { return c(n + k - 1, k); }

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    sieve(); init();
    int q; cin >> q; while (q--) {
        int n, f; cin >> n >> f;
        int ans = h(f, n - f);
        // cout << "ans = " << ans << endl;
        for (int d : pr) if (n % d == 0) {
            int m = n / d;
            ans = sub(ans, h(f , m - f));
        }
        cout << ans << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int maxn = 2e5 + 10, mod = 1e9 + 7;
int f[maxn], invf[maxn];
bool v[maxn], p[maxn], used[maxn];
vector<int> pr;

inline int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; }
inline int sub(int a, int b) { return a - b < 0 ? a - b + mod : a - b; }
inline int mul(int a, int b) { return a * 1ll * b % mod; }

void sieve() {
    for (int i = 2; i < maxn; ++i) {
        if (!v[i]) pr.push_back(i), p[i] = true;
        for (int j = 0; i * pr[j] < maxn; ++j) {
            v[i * pr[j]] = true;
            if (i % pr[j] == 0) break;
        }
    }
}

int fpow(int a, int n) {
    int ret = 1;
    for (; n; n >>= 1) {
        if (n & 1) ret = mul(ret, a);
        a = mul(a, a);
    }
    return ret;
}

void init() {
    f[0] = 1; invf[0] = 1;
    for (int i = 1; i < maxn; ++i) {
        f[i] = mul(f[i - 1], i);
        invf[i] = fpow(f[i], mod - 2);
    }
}

inline int c(int n, int k) { return n < k || n < 0 || k < 0 ? 0 : mul(f[n], mul(invf[k], invf[n - k])); }
inline int h(int n, int k) { return c(n + k - 1, k); }

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    sieve(); init();
    int q; cin >> q; while (q--) {
        int n, f; cin >> n >> f;
        int tn = n, ans = h(f, n - f);
        size_t ptr = 0;
        vector<int> di;
        while (tn > 1) {
            if (tn % pr[ptr] == 0) di.push_back(pr[ptr]);
            while (tn % pr[ptr] == 0) tn /= pr[ptr];
            ++ptr;
        }
        int sz = di.size();
        for (int m = 1; m < (1 << sz); ++m) {
            int d = 1;
            for (size_t i = 0; i < di.size(); ++i) {
                if ((1 << i) & m) d *= di[i];
            }
            int c = h(f, n / d - f);
            if (__builtin_popcount(m) & 1) ans = sub(ans, c);
            else ans = add(ans, c);
        }
        cout << ans << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int maxn = 2e5 + 10, mod = 1e9 + 7;
int f[maxn], invf[maxn];
bool v[maxn], p[maxn];
vector<int> pr;

inline int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; }
inline int sub(int a, int b) { return a - b < 0 ? a - b + mod : a - b; }
inline int mul(int a, int b) { return a * 1ll * b % mod; }

void sieve() {
    for (int i = 2; i < maxn; ++i) {
        if (!v[i]) pr.push_back(i), p[i] = true;
        for (int j = 0; i * pr[j] < maxn; ++j) {
            v[i * pr[j]] = true;
            if (i % pr[j] == 0) break;
        }
    }
}

int fpow(int a, int n) {
    int ret = 1;
    for (; n; n >>= 1) {
        if (n & 1) ret = mul(ret, a);
        a = mul(a, a);
    }
    return ret;
}

void init() {
    f[0] = 1; invf[0] = 1;
    for (int i = 1; i < maxn; ++i) {
        f[i] = mul(f[i - 1], i);
        invf[i] = fpow(f[i], mod - 2);
    }
}

inline int c(int n, int k) { return n < k ? 0 : mul(f[n], mul(invf[k], invf[n - k])); }
inline int h(int n, int k) { return c(n + k - 1, k); }

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    sieve(); init();
    int q; cin >> q; while (q--) {
        int n, f; cin >> n >> f;
        int ans = h(f, n - f);
        // cout << "ans = " << ans << endl;
        for (int d : pr) if (n % d == 0) {
            int m = n / d;
            // cout << "f = " << f << " m - f" << endl;
            ans = sub(ans, h(f , m - f));
        }
        cout << ans << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}

const ll MOD = 1000000007;

const int SZ = 312345;
ll inv[SZ];
ll fact[SZ];
ll fact_inv[SZ];
ll choose(int n, int r) {
  if (n < 0 || r < 0 || n < r) return 0;
  return fact[n] * fact_inv[n-r] % MOD * fact_inv[r] % MOD;
}

vector<int> primes;
bool isPrime[SZ];

void make_primes() {
  if (primes.size() > 0) return;
  memset(isPrime, true, sizeof(isPrime));
  isPrime[0] = isPrime[1] = false;
  for (int i = 2; i * i < SZ; i++)
    if (isPrime[i])
      for (int j = i * i; j < SZ; j += i)
        isPrime[j] = false;
  REP(i, SZ) if (isPrime[i]) primes.push_back(i);
}

const int MAX_N = SZ;
int mobius[MAX_N];
void make_mobius() {
  for(int i = 0; i < MAX_N; i++) mobius[i] = 1;
  for(int i = 2; i < MAX_N; i++)
   if (isPrime[i])
     for(int j = i; j < MAX_N; j += i)
       if ( j / i % i == 0 ) mobius[j] = 0;
       else mobius[j] *= -1;
  // pv(mobius, mobius + 31);
  // 1 1 -1 -1 0 -1 1 -1 0 0 1 -1 0 -1 1 1 0 -1 0 -1 0 1 1 -1 0 0 1 0 0 -1 -1
}

ll H(int n, int m) {
  return choose(n + m - 1, n);
}

ll p(int n, int f) {
  if (n < f) return 0;
  return H(n-f, f);
}

int main2() {
  int q = nextInt();
  for (;q--;) {
    int n = nextInt();
    int f = nextInt();
    ll ans = 0;
    for (int d = 1; d * d <= n; d++) {
      if (n % d == 0) {
        int x = d;
        if (mobius[x]) {
          // cout << x << " " << mobius[x] << " " << p(n/x, f) << endl;
          ans += mobius[x] * p(n / x, f);
          ans %= MOD;
        }
        if (d * d != n) {
          int x = n / d;
          if (mobius[x]) {
            // cout << x << " " << mobius[x] << " " << p(n/x, f) << endl;
            ans += mobius[x] * p(n / x, f);
            ans %= MOD;
          }
        }
      }
    }
    printf("%d\n", (int)ans);
  }
  return 0;
}

int main() {
  make_primes();
  make_mobius();

  inv[1] = 1;
  for (int i = 2; i < SZ; i++) inv[i] = inv[(int) (MOD % i)] * (MOD - MOD / i) % MOD;
  fact[0] = 1;
  for (int i = 1; i < SZ; i++) fact[i] = fact[i-1] * i % MOD;
  fact_inv[0] = 1;
  for (int i = 1; i < SZ; i++) fact_inv[i] = fact_inv[i-1] * inv[i] % MOD;

  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}

const ll MOD = 1000000007;

const int SZ = 312345;
ll inv[SZ];
ll fact[SZ];
ll fact_inv[SZ];
ll choose(int n, int r) {
  if (n < 0 || r < 0 || n < r) return 0;
  return fact[n] * fact_inv[n-r] % MOD * fact_inv[r] % MOD;
}

vector<int> primes;
bool isPrime[SZ];

void make_primes() {
  if (primes.size() > 0) return;
  memset(isPrime, true, sizeof(isPrime));
  isPrime[0] = isPrime[1] = false;
  for (int i = 2; i * i < SZ; i++)
    if (isPrime[i])
      for (int j = i * i; j < SZ; j += i)
        isPrime[j] = false;
  REP(i, SZ) if (isPrime[i]) primes.push_back(i);
}

const int MAX_N = SZ;
int mobius[MAX_N];
void make_mobius() {
  for(int i = 0; i < MAX_N; i++) mobius[i] = 1;
  for(int i = 2; i < MAX_N; i++)
   if (isPrime[i])
     for(int j = i; j < MAX_N; j += i)
       if ( j / i % i == 0 ) mobius[j] = 0;
       else mobius[j] *= -1;
  // pv(mobius, mobius + 31);
  // 1 1 -1 -1 0 -1 1 -1 0 0 1 -1 0 -1 1 1 0 -1 0 -1 0 1 1 -1 0 0 1 0 0 -1 -1
}

ll H(int n, int m) {
  return choose(n + m - 1, n);
}

ll p(int n, int f) {
  if (n < f) return 0;
  return H(n-f, f);
}

int main2() {
  int q = nextInt();
  for (;q--;) {
    int n = nextInt();
    int f = nextInt();
    ll ans = 0;
    for (int d = 1; d * d <= n; d++) {
      if (n % d == 0) {
        int x = d;
        if (mobius[x]) {
          // cout << x << " " << mobius[x] << " " << p(n/x, f) << endl;
          ans += mobius[x] * p(n / x, f);
          ans %= MOD;
        }
        if (d * d != n) {
          int x = n / d;
          if (mobius[x]) {
            // cout << x << " " << mobius[x] << " " << p(n/x, f) << endl;
            ans += mobius[x] * p(n / x, f);
            ans %= MOD;
          }
        }
      }
    }
    ans = ((ans % MOD) + MOD) % MOD;
    printf("%lld\n", ans);
  }
  return 0;
}

int main() {
  make_primes();
  make_mobius();

  inv[1] = 1;
  for (int i = 2; i < SZ; i++) inv[i] = inv[(int) (MOD % i)] * (MOD - MOD / i) % MOD;
  fact[0] = 1;
  for (int i = 1; i < SZ; i++) fact[i] = fact[i-1] * i % MOD;
  fact_inv[0] = 1;
  for (int i = 1; i < SZ; i++) fact_inv[i] = fact_inv[i-1] * inv[i] % MOD;

  for (;!cin.eof();cin>>ws)
    main2();
  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);
}

bool vis[N+5];
ll dp[N+5];

ll solve(ll n, ll f) {

	if (f>n) return 0ll;
	if (f==1) {
		if (n>1) {
			return 0;
		} else {
			return 1;
		}
	}
	if (vis[n]) return dp[n];
	vis[n] = true;
	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 dp[n] = ans;
}

struct triple {
	ll n, f;
	int ind;

	bool operator<(const triple& other) const {
		return f<other.f;
	}
};

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;
	vector<triple> query(num_tests);
	for (int tc=1; tc<=num_tests; tc++) {
		// printf("Case #%d: ", tc);
		// cout << "Case #" << tc << ": ";
		ll n, f;
		scanf("%lld %lld", &query[tc-1].n, &query[tc-1].f);
		query[tc-1].ind = tc-1;
	}

	sort(query.begin(), query.end());

	int curr_f = -1;
	vector<ll> ans(num_tests);

	for (int i=0; i<num_tests; i++) {
		if (query[i].f!=curr_f) {
			memset(vis, 0, sizeof vis);
			curr_f = query[i].f;
		}

		ans[query[i].ind] = solve(query[i].n, query[i].f);

	}

	for (ll i: ans) {
		printf("%lld\n", i);
	}
	printclock
	return 0;
}