#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long long ff[100100], inv_ff[100100];
int q, n, f, prime[100100], sqr[100100], mu[100100], ans;
vector<int> divi[100100];
long long inv_mod(long long x) {
  long long ret = 1LL, y = MOD - 2;
  while (y) {
    if (y & 1) ret = (ret * x) % MOD;
    x = (x * x) % MOD, y >>= 1;
  }
  return ret;
}
long long C(int x, int y) {
  if (y > x) return 0;
  return (ff[x] * ((inv_ff[y] * inv_ff[x - y]) % MOD)) % MOD;
}
void precompute() {
  inv_ff[0] = 1LL;
  ff[0] = 1LL;
  for (int i = 1; i <= 100099; i++) {
    ff[i] = (ff[i - 1] * i) % MOD;
    inv_ff[i] = inv_mod(ff[i]);
    prime[i] = 1;
  }
  for (int i = 1; i <= 100099; i++) {
    for (int j = i; j <= 100099; j += i) {
      divi[j].push_back(i);
    }
  }
  prime[0] = 0, prime[1] = 0;
  for (int i = 2; i <= 100099; i++) {
    if (prime[i] == 1) {
      for (int j = i + i; j <= 100099; j += i) prime[j] = 0;
    }
  }
  for (int i = 2; i * i <= 100099; i++) {
    for (int j = (i * i); j <= 100099; j += (i * i)) sqr[j] = 1;
  }
  for (int i = 1; i <= 100099; i++) {
    if (sqr[i] == 1) continue;
    int cnt = 0;
    for (__typeof(divi[i].begin()) d(divi[i].begin()); d != divi[i].end(); d++)
      if (prime[*d] == 1) cnt++;
    mu[i] = (cnt % 2 == 1) ? -1 : 1;
  }
  return;
}
int main() {
  precompute();
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d", &n, &f);
    if (n == 1 and f == 1) {
      printf("1\n");
      continue;
    }
    if (n > 1 and f == 1) {
      printf("0\n");
      continue;
    }
    ans = 0;
    for (__typeof(divi[n].begin()) d(divi[n].begin()); d != divi[n].end();
         d++) {
      ans = (ans + mu[*d] * C((n / (*d)) - 1, f - 1)) % MOD;
      if (ans < 0)
        ans += MOD;
      else if (ans >= MOD)
        ans -= MOD;
    }
    printf("%d\n", ans);
  }
  return 0;
}
