#include <bits/stdc++.h>
using namespace std;
inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}
const int N = 1e5 + 10;
const int MOD = 1e9 + 7;
const long double eps = 1e-12;
map<pair<int, int>, int> mp;
int q, fact[N], inv[N];
vector<int> v[N];
int power(int n, int f) {
  if (f == 0) return 1;
  if (f == 1) return n;
  long long x = power(n, f >> 1);
  x %= MOD;
  x = x * x;
  x %= MOD;
  if (f & 1) {
    long long s = x * n;
    s %= MOD;
    return s;
  }
  return (1LL * x) % MOD;
}
int choose(int n, int f) {
  long long iv = (1LL * inv[f] * inv[n - f]) % MOD;
  return (1LL * fact[n] * iv) % MOD;
}
int solve(int n, int f) {
  if (mp.find({n, f}) != mp.end()) return mp[{n, f}];
  if (n < f) return 0;
  if (n == f) return 1;
  int res = choose(n - 1, f - 1);
  for (int i = 0; i < v[n].size(); i++) {
    res -= solve(v[n][i], f);
    if (res < 0) res += MOD;
  }
  mp[{n, f}] = res;
  return res;
}
int main() {
  for (int i = 2; i < N; i++)
    for (int j = i + i; j < N; j += i) v[j].push_back(i);
  fact[0] = 1;
  for (int i = 1; i < N; i++)
    fact[i] = (1LL * fact[i - 1] * i) % MOD, inv[i] = power(fact[i], MOD - 2);
  q = in();
  while (q--) {
    int n = in(), f = in();
    printf("%d\n", solve(n, f));
  }
  return 0;
}
