#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T gcd(T a, T b) {
  return (b) == 0 ? (a) : gcd((b), ((a) % (b)));
}
template <class T>
inline T lcm(T a, T b) {
  return ((a) / gcd((a), (b)) * (b));
}
template <class T>
inline T BigMod(T Base, T power, T M = 1000000007) {
  if (power == 0) return 1;
  if (power & 1)
    return ((Base % M) * (BigMod(Base, power - 1, M) % M)) % M;
  else {
    T y = BigMod(Base, power / 2, M) % M;
    return (y * y) % M;
  }
}
template <class T>
inline T ModInv(T A, T M = 1000000007) {
  return BigMod(A, M - 2, M);
}
int fx[] = {-1, +0, +1, +0, +1, +1, -1, -1, +0};
int fy[] = {+0, -1, +0, +1, +1, -1, +1, -1, +0};
int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
long long f[500005], inv[500005];
vector<int> v[500005];
int miu[500005], mark[500005];
void mobius(int n) {
  for (int i = 0; i <= n; i++) miu[i] = 1;
  miu[0] = 0;
  miu[1] = 1;
  for (int i = 2; i <= n; i++) {
    if (mark[i]) continue;
    miu[i] = -1;
    for (int j = i * 2; j <= n; j += i) {
      if (miu[j] != 0) {
        if (j % (i * i) == 0)
          miu[j] = 0;
        else
          miu[j] *= -1;
        mark[j] = 1;
      }
    }
  }
}
void pre() {
  f[0] = 1;
  for (int i = 1; i < 500005; i++) f[i] = (f[i - 1] * i) % 1000000007;
  inv[500005 - 1] = ModInv<long long>(f[500005 - 1]);
  for (int i = 500005 - 2; i >= 0; i--)
    inv[i] = (inv[i + 1] * (i + 1)) % 1000000007;
  for (int i = 1; i < 500005; i++) {
    for (int j = i; j < 500005; j += i) v[j].push_back(i);
  }
}
long long pk(int n, int r) {
  n--;
  r--;
  if (n < r) return 0;
  return ((f[n] * inv[r]) % 1000000007 * inv[n - r]) % 1000000007;
}
long long giveres(int n, int r) {
  long long ans = 0;
  for (auto it : v[n]) {
    ans += (miu[it] * pk(n / it, r));
    if (ans < 0) ans += 1000000007;
    if (ans >= 1000000007) ans %= 1000000007;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  pre();
  mobius(500005 - 1);
  int t;
  cin >> t;
  while (t--) {
    int n, r;
    cin >> n >> r;
    cout << giveres(n, r) << endl;
  }
  return 0;
}
