#include <bits/stdc++.h>
#pragma GCC optimize("O3")
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e5 + 5;
const double eps = 1e-9;
using namespace std;
long long fac[MAXN], inv[MAXN];
int sieve[MAXN], cnt[MAXN], fl[MAXN];
long long bin(long long a, long long b) {
  long long ret = 1;
  while (b) {
    if (b & 1) ret = (ret * a) % MOD;
    a = (a * a) % MOD;
    b /= 2ll;
  }
  return ret;
}
long long ncr(long long n, long long k) {
  if (n < k) return 0;
  return (fac[n] * inv[n - k] % MOD) * inv[k] % MOD;
}
int main() {
  for (int i = 2; i < MAXN; i++) {
    if (!sieve[i])
      for (int j = i; j < MAXN; j += i) sieve[j] = i;
    int x = i;
    fl[x] = 1;
    while (x > 1) {
      int cur = sieve[x];
      while (sieve[x] == cur) {
        x /= sieve[x];
        if (sieve[x] == cur) fl[i] = 0;
      }
      cnt[i]++;
    }
  }
  fac[0] = 1;
  for (long long i = 1; i < MAXN; i++) fac[i] = fac[i - 1] * i % MOD;
  inv[0] = 1;
  for (long long i = 1; i < MAXN; i++) inv[i] = bin(fac[i], MOD - 2);
  int q;
  scanf("%d", &(q));
  for (int i = 0; i < q; i++) {
    int n, f;
    scanf("%d", &(n)), scanf("%d", &(f));
    long long pr = ncr(n - 1, f - 1);
    for (long long x = 2; x * x <= n && f > 1; x++) {
      if (n % x != 0) continue;
      if (fl[x]) {
        if (cnt[x] & 1)
          pr = (pr - ncr(n / x - 1, f - 1) + MOD) % MOD;
        else
          pr = (pr + ncr(n / x - 1, f - 1)) % MOD;
      }
      if (x != n / x && fl[n / x]) {
        if (cnt[n / x] & 1)
          pr = (pr - ncr(x - 1, f - 1) + MOD) % MOD;
        else
          pr = (pr + ncr(x - 1, f - 1)) % MOD;
      }
    }
    if (f == 1 && n != 1) pr = 0;
    printf("%I64d\n", (pr));
  }
  return 0;
}
