#include <bits/stdc++.h>
const int mod = 1e9 + 7;
const int w = 1e5;
std::map<std::pair<int, int>, int> st;
std::vector<int> d[w + 10];
int a[w + 10];
int ft[w + 10];
inline int pmod(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1) res = (1ll * res * a) % mod;
    a = (1ll * a * a) % mod;
    b >>= 1;
  }
  return res;
}
inline int calc(int n, int k) {
  if (k > n) return 0;
  return (1ll * ft[n] * pmod((1ll * ft[k] * ft[n - k]) % mod, mod - 2)) % mod;
}
int solve(int n, int m) {
  if (m < n) return 0;
  std::pair<int, int> x = std::pair<int, int>(n, m);
  if (st.find(x) != st.end()) return st[x];
  long long res = calc(m - 1, n - 1);
  int sz = int(d[m].size());
  for (int i = 0; i < sz; ++i) res -= solve(n, d[m][i]);
  return st[x] = res % mod;
}
int main() {
  ft[0] = 1;
  for (int i = 1; i <= w; ++i) ft[i] = (1ll * ft[i - 1] * i) % mod;
  for (int i = 2; i <= w; ++i) d[i].push_back(1);
  for (int i = 2; i << 1 <= w; ++i)
    for (int j = i << 1; j <= w; j += i) d[j].push_back(i);
  int tt;
  for (scanf("%d", &tt); tt--;) {
    int n, m;
    scanf("%d %d", &m, &n);
    int ans = (solve(n, m) % mod + mod) % mod;
    printf("%d\n", ans);
  }
}
