#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
vector<long long int> fact(200005);
vector<long long int> invfact(200005);
bool sieve[200005];
int SPF[200005];
long long int binpow(long long int a, long long int b) {
  long long int res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % 1000000007;
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return res;
}
pair<long long int, long long int> decompose(long long int n) {
  int ctr = 0;
  vector<long long int> p;
  while (n > 1) {
    int q = SPF[n];
    p.push_back(q);
    while (n % q == 0) n /= q;
  }
  long long int prod = 1;
  for (auto i : p) prod *= i;
  return {prod, p.size()};
}
long long int nck(long long int a, long long int b) {
  if (a < b) return 0;
  return fact[a] * invfact[b] % 1000000007 * invfact[a - b] % 1000000007;
}
void solve() {
  int n, k;
  cin >> n >> k;
  if (k == 1) {
    if (n == 1)
      cout << 1 << "\n";
    else
      cout << 0 << "\n";
    return;
  }
  long long int ans = nck(n - 1, k - 1);
  set<pair<long long int, long long int>> reducedpf;
  for (long long int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      reducedpf.insert(decompose(i));
      reducedpf.insert(decompose(n / i));
    }
  }
  for (auto i : reducedpf) {
    if (i.second % 2)
      ans = (ans - nck(n / i.first - 1, k - 1)) % 1000000007;
    else
      ans = (ans + nck(n / i.first - 1, k - 1)) % 1000000007;
  }
  ans += 1000000007;
  ans %= 1000000007;
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  fact[0] = 1;
  invfact[0] = 1;
  for (long long int i = 2; i <= 100005; i++) {
    if (!sieve[i]) {
      SPF[i] = i;
      for (long long int j = i * i; j <= 100005; j += i) {
        if (SPF[j] == 0) SPF[j] = i;
        SPF[j] = min(SPF[j], SPF[i]);
        sieve[j] = true;
      }
    }
  }
  for (long long int i = 1; i <= 100005; i++) {
    fact[i] = i * fact[i - 1] % 1000000007;
    invfact[i] = binpow(fact[i], 1000000007 - 2);
  }
  int t;
  cin >> t;
  while (t--) solve();
}
