#include <bits/stdc++.h>
using namespace std;
const int N = 111111;
vector<int> P[N];
const int MOD = 1000000007;
long long d[N], e[N];
long long quick_pow(long long b, long long n) {
  long long ret = 1;
  while (n != 0) {
    if (n % 2 == 1) ret = ret * b % MOD;
    b = b * b % MOD;
    n /= 2;
  }
  return ret;
}
long long C(long long n, long long m) {
  return d[n] * e[n - m] % MOD * e[m] % MOD;
}
int pri[N], pnum, mu[N], vis[N];
void mobius(int n) {
  pnum = 0, vis[1] = mu[1] = 1;
  for (int i = 2; i <= n; i++) {
    if (!vis[i]) {
      pri[pnum++] = i;
      mu[i] = -1;
    }
    for (int j = 0; j < pnum; j++) {
      if (i * pri[j] > n) break;
      vis[i * pri[j]] = 1;
      if (i % pri[j] == 0) {
        mu[i * pri[j]] = 0;
        break;
      }
      mu[i * pri[j]] = -mu[i];
    }
  }
}
void init() {
  d[0] = e[0] = 1;
  for (int i = 1; i < N; i++) {
    d[i] = d[i - 1] * i % MOD;
    e[i] = quick_pow(d[i], MOD - 2);
  }
  for (int i = 2; i < N; i++)
    for (int j = i; j < N; j += i) P[j].push_back(i);
  mobius(N - 1);
}
int q, n, f;
long long F(int n) { return C(n - 1, f - 1); }
long long solve() {
  long long ans = F(n);
  for (int i = 0; i < P[n].size(); i++) {
    int d = P[n][i];
    if (n / d >= f) {
      ans = (ans + mu[d] * F(n / d)) % MOD;
    }
  }
  return (ans + MOD) % MOD;
}
int main() {
  init();
  scanf("%d", &q);
  while (q--) {
    scanf("%d %d", &n, &f);
    cout << solve() << endl;
  }
}
