#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const long long mod = 1e9 + 7;
long long fact[N], inv[N];
long long dp[N];
int done[N];
int q;
int id;
long long n, f;
vector<long long> prime;
vector<long long> g[N];
long long mobius[N];
bool composite[N];
void mobi() {
  memset(composite, false, sizeof composite);
  mobius[1] = 1;
  for (int i = 2; i < N; i++) {
    if (!composite[i]) {
      prime.push_back(i);
      mobius[i] = -1;
    }
    for (int j = 0; j < prime.size() and i * prime[j] < N; j++) {
      composite[i * prime[j]] = true;
      if (i % prime[j] == 0) {
        mobius[i * prime[j]] = 0;
        break;
      } else {
        mobius[i * prime[j]] = mobius[i] * mobius[prime[j]];
      }
    }
  }
}
long long bigmod(long long x, long long y) {
  long long res = 1;
  while (y) {
    if (y & 1) res = (res * x) % mod;
    y >>= 1;
    x = (x * x) % mod;
  }
  return res;
}
void pre() {
  fact[0] = 1, inv[0] = bigmod(1, mod - 2);
  for (int i = 1; i < N; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
    inv[i] = bigmod(fact[i], mod - 2);
    for (int j = i; j < N; j += i) {
      g[j].push_back(i);
    }
  }
}
long long ncr(long long n, long long r) {
  if (n < r or r < 0) return 0;
  long long up = (fact[n] * inv[r]) % mod;
  up = (up * inv[n - r]) % mod;
  return up;
}
long long go(long long n, long long f) {
  long long res = 0;
  for (auto x : g[n]) {
    res = (res + mobius[n / x] * ncr(x - 1, f - 1)) % mod;
    if (res < 0) res += mod;
  }
  return res;
}
int main() {
  mobi();
  pre();
  scanf("%d", &q);
  while (q--) {
    scanf("%lld %lld", &n, &f);
    printf("%lld\n", go(n, f));
  }
}
