#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 30, Mod = 1e9 + 7;
const long long SQ = 330;
long long dp[N];
vector<long long> Div[N];
long long f[N], I[N];
bool vis[N];
inline long long _sub(long long x, long long y) {
  long long res = x - y;
  if (res < 0) res += Mod;
  res %= Mod;
  return res;
}
inline long long _mul(long long x, long long y) { return (x * y) % Mod; }
long long _pow(long long x, long long y) {
  if (!x) return 0;
  if (!y) return 1;
  long long t = _pow(x, y / 2);
  t *= t;
  t %= Mod;
  if (y % 2 == 1) return _mul(t, x);
  return t;
}
inline void pre() {
  for (int i = 1; i < N; i++) {
    for (int j = i * 2; j < N; j += i) Div[j].push_back(i);
  }
  f[0] = 1;
  for (int i = 1; i < N; i++) f[i] = _mul(f[i - 1], i);
  I[N - 1] = _pow(f[N - 1], Mod - 2);
  for (int i = N - 2; i > 0; i--) {
    I[i] = _mul(i + 1, I[i + 1]);
  }
}
inline long long C(long long r, long long n) {
  if (r == 0) return 1;
  if (r > n or n < 0) return 0;
  if (r == n) return 1;
  return _mul(_mul(f[n], I[r]), I[n - r]);
}
long long solve(long long n, long long f) {
  if (f > n) return 0;
  if (vis[n]) return dp[n];
  vis[n] = 1;
  long long res = C(f - 1, n - 1);
  for (auto d : Div[n]) {
    res = _sub(res, solve(d, f));
  }
  return dp[n] = res;
}
int main() {
  pre();
  long long q;
  scanf("%lld", &q);
  while (q--) {
    long long n, f;
    scanf("%lld%lld", &n, &f);
    if (n < f) {
      cout << 0 << "\n";
      continue;
    }
    for (auto u : Div[n]) dp[u] = 0, vis[u] = 0;
    dp[n] = 0, vis[n] = 0;
    long long p = solve(n, f);
    printf("%lld", p);
    printf("\n");
  }
  return (0);
}
