#include <bits/stdc++.h>
using namespace std;
const int maxn = 1001000;
const int MOD = 1e9 + 7;
int cnt;
int a[maxn], Count[maxn];
long long Pow[maxn], INV[maxn];
bool check[maxn];
int prime[maxn], mu[maxn], tot;
void Moblus() {
  memset(check, false, sizeof(check));
  mu[1] = 1, tot = 0;
  for (int i = 2; i < maxn; i++) {
    if (!check[i]) {
      prime[tot++] = i;
      mu[i] = -1;
    }
    for (int j = 0; j < tot && i * prime[j] < maxn; j++) {
      check[i * prime[j]] = true;
      if (i % prime[j])
        mu[i * prime[j]] = -mu[i];
      else {
        mu[i * prime[j]] = 0;
        break;
      }
    }
  }
}
void solve(int n) {
  int num = sqrt(n + 1);
  for (int i = 1; i <= num; i++) {
    if (n % i == 0) {
      a[cnt++] = i;
      if (i * i != n) a[cnt++] = n / i;
    }
  }
}
long long inv(long long a, long long m) {
  if (a == 1) return 1;
  return inv(m % a, m) * (m - m / a) % m;
}
int main() {
  Moblus();
  int _, n, f;
  Pow[0] = 1;
  for (int i = 1; i < maxn; i++) Pow[i] = Pow[i - 1] * i % MOD;
  for (int i = 0; i < maxn; i++) INV[i] = inv(Pow[i], MOD);
  scanf("%d", &_);
  while (_--) {
    scanf("%d%d", &n, &f);
    cnt = 0;
    solve(n);
    sort(a, a + cnt);
    long long ans = 0;
    for (int i = 0; i < cnt; i++) {
      if (n / a[i] < f) break;
      Count[a[i]] =
          Pow[n / a[i] - 1] * INV[n / a[i] - f] % MOD * INV[f - 1] % MOD;
      ans = (ans + 1LL * Count[a[i]] * mu[a[i]]) % MOD;
    }
    printf("%lld\n", (ans + MOD) % MOD);
  }
  return 0;
}
