#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int p[100010], cnt, miu[100010];
bool vis[100010];
long long fac[100010], inv[100010], facinv[100010];
void init() {
  miu[1] = 1;
  for (int i = 2; i <= 100000; i++) {
    if (!vis[i]) {
      p[++cnt] = i;
      miu[i] = -1;
    }
    for (int j = 1; j <= cnt && i * p[j] <= 100000; j++) {
      vis[i * p[j]] = 1;
      if (i % p[j] == 0) {
        miu[i * p[j]] = 0;
        break;
      }
      miu[i * p[j]] = -miu[i];
    }
  }
  fac[0] = 1;
  for (int i = 1; i <= 100000; i++) fac[i] = fac[i - 1] * i % mod;
  inv[1] = 1;
  for (int i = 2; i <= 100000; i++)
    inv[i] = (mod - mod / i) * inv[mod % i] % mod;
  facinv[0] = 1;
  for (int i = 1; i <= 100000; i++) facinv[i] = facinv[i - 1] * inv[i] % mod;
}
long long C(long long n, long long k) {
  if (k < 0 || k > n) return 0;
  if (k == 0 || k == n) return 1;
  return fac[n] * facinv[k] % mod * facinv[n - k] % mod;
}
long long cal(int n, int f) { return C(n - 1, f - 1); }
void solve(int n, int f) {
  long long ans = 0;
  for (int i = 1; i * i <= n; i++)
    if (n % i == 0) {
      ans += miu[i] * cal(n / i, f) % mod;
      if (i * i != n) ans += miu[n / i] * cal(i, f) % mod;
      ans %= mod;
    }
  cout << (ans + mod) % mod << endl;
}
int main() {
  init();
  int q;
  cin >> q;
  while (q--) {
    int n, f;
    scanf("%d%d", &n, &f);
    solve(n, f);
  }
  return 0;
}
