#include <bits/stdc++.h>
using namespace std;
template <typename T>
void r1(T &x) {
  x = 0;
  char c(getchar());
  int f(1);
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') f = -1;
  for (; '0' <= c && c <= '9'; c = getchar()) x = (x * 10) + (c ^ 48);
  x *= f;
}
const long long maxn = 4e5 + 5;
const long long maxm = maxn << 1;
const long long mod = 1e9 + 7;
typedef long long room[maxn];
long long n, f;
long long vis[maxn], pr[maxn], tot, mu[maxn];
long long fac[maxn], inv[maxn];
void init(long long x) {
  mu[1] = 1;
  for (long long i = 2; i <= x; ++i) {
    if (!vis[i]) pr[++tot] = i, mu[i] = -1;
    for (long long j = 1, k; k = 1ll * pr[j] * i, j <= tot && k <= x; ++j) {
      vis[k] = 1;
      if (!(i % pr[j])) {
        mu[k] = 0;
        break;
      }
      mu[k] = -mu[i];
    }
  }
}
long long ksm(long long x, long long mi) {
  long long res(1);
  while (mi) {
    if (mi & 1) res = 1ll * res * x % mod;
    mi >>= 1;
    x = 1ll * x * x % mod;
  }
  return res;
}
inline long long getmu(long long x) { return (mu[x] + mod) % mod; }
long long C(long long a, long long b) {
  if (a < b) return 0;
  return 1ll * fac[a] * inv[b] % mod * inv[a - b] % mod;
}
const long long N = 1e5;
inline void update(long long &x, long long y) { x = (x + y + mod) % mod; }
signed main() {
  long long i, j, q;
  fac[0] = 1;
  for (i = 1; i <= N; ++i) fac[i] = 1ll * fac[i - 1] * i % mod;
  inv[N] = ksm(fac[N], mod - 2);
  for (i = N - 1; ~i; --i) inv[i] = 1ll * inv[i + 1] * (i + 1) % mod;
  init(N);
  r1(q);
  while (q--) {
    r1(n), r1(f);
    long long ans(0);
    for (long long i = 1; 1ll * i * i <= n; ++i) {
      if (!(n % i)) {
        update(ans, 1ll * C(i - 1, f - 1) * getmu(n / i) % mod);
        if (i * i != n) update(ans, 1ll * C(n / i - 1, f - 1) * getmu(i) % mod);
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
