#include <bits/stdc++.h>
using namespace std;
const int Maxn = 2e5 + 10;
const int Inf = 0x7f7f7f7f;
const long long Inf_ll = 1ll * Inf * Inf;
const int Mod = 1e9 + 7;
const double eps = 1e-7;
void r(int &p) {
  char c = getchar();
  int x = 0, fh = 0;
  while (c < '0' || c > '9') {
    fh |= c == '-';
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  p = fh ? -x : x;
}
long long inv[Maxn], fac[Maxn], finv[Maxn];
void Init(int n) {
  inv[0] = inv[1] = fac[0] = finv[0] = 1;
  for (int i = 2; i <= n; i++)
    inv[i] = 1ll * (Mod - Mod / i) * inv[Mod % i] % Mod;
  for (int i = 1; i <= n; i++)
    fac[i] = fac[i - 1] * i % Mod, finv[i] = finv[i - 1] * inv[i] % Mod;
}
int prim[Maxn], tol, mu[Maxn], phi[Maxn];
bool vis[Maxn];
void Get(int n) {
  mu[1] = phi[1] = 1;
  for (int i = 2; i <= n; i++) {
    if (!vis[i]) prim[++tol] = i, mu[i] = -1, phi[i] = i - 1;
    for (int j = 1; j <= tol && i * prim[j] <= n; j++) {
      vis[i * prim[j]] = true;
      if (i % prim[j] == 0) {
        phi[i * prim[j]] = phi[i] * prim[j];
        break;
      }
      mu[i * prim[j]] = -mu[i];
      phi[i * prim[j]] = phi[i] * (prim[j] - 1);
    }
  }
}
long long C(int n, int m) {
  if (n < m) return 0;
  return fac[n] * finv[m] % Mod * finv[n - m] % Mod;
}
long long F(int n, int i, int k) { return C(n / i - 1, k - 1); }
int main() {
  Get(Maxn - 10);
  Init(Maxn - 10);
  int T;
  scanf("%d", &T);
  for (int _ = 1; _ <= T; _++) {
    int n, k;
    scanf("%d %d", &n, &k);
    if (k == 1 && n != 1) {
      puts("0");
      continue;
    }
    long long ans = 0;
    for (int i = 1; i * i <= n; i++) {
      if (n % i == 0) {
        ans = (ans + mu[i] * F(n, i, k) % Mod + Mod) % Mod;
        if (i * i != n)
          ans = (ans + mu[n / i] * F(n, n / i, k) % Mod + Mod) % Mod;
      }
    }
    printf("%lld\n", ans % Mod);
  }
  return 0;
}
