#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
long long n, m, a, b, c, k, temp, x, y;
const int MAXN = 1e5 + 11;
inline long long max(long long a, long long b) { return ((a > b) ? a : b); }
inline long long min(long long a, long long b) { return ((a > b) ? b : a); }
inline long long gcd(long long a, long long b) {
  if (b == 0) return a;
  a %= b;
  return gcd(b, a);
}
inline vector<long long> read(int n) {
  vector<long long> v(n);
  for (int i = 0; i < v.size(); i++) cin >> v[i];
  return v;
}
const int mod = 1e9 + 7;
vector<long long> v[MAXN];
long long factorial[2 * MAXN], ans[MAXN], Inverse[2 * MAXN];
long long power(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long modInverse(long long a) { return power(a, mod - 2); }
void init() {
  factorial[0] = 1;
  for (int i = 1; i < 2 * MAXN; i++) factorial[i] = factorial[i - 1] * i % mod;
  for (int i = 0; i < 2 * MAXN; i++) Inverse[i] = modInverse(factorial[i]);
}
long long binomial_coefficient(int n, int k) {
  return factorial[n] * Inverse[k] % mod * Inverse[n - k] % mod;
}
void solveforthiscase(const int& test) {
  for (int i = MAXN - 1; i >= 1; i--) {
    for (int j = i; j < MAXN; j += i) {
      v[j].push_back(i);
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int n, f;
    cin >> n >> f;
    long long t = binomial_coefficient(n - 1, f - 1) % mod;
    for (auto x : v[n]) {
      long long val = n / x;
      val--;
      if (val < f - 1 || x == 1) continue;
      ans[x] += binomial_coefficient(val, f - 1) % mod;
      ans[x] %= mod;
      for (auto y : v[x]) {
        if (y == x || y == 1) continue;
        ans[y] = (ans[y] - ans[x] + mod) % mod;
      }
      t -= ans[x];
      t += mod;
      t %= mod;
    }
    for (auto x : v[n]) ans[x] = 0;
    cout << t << '\n';
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  clock_t start, end;
  start = clock();
  int test = 1;
  init();
  for (int i = 1; i <= test; i++) solveforthiscase(i);
  end = clock();
  long double t_t = (long double)(end - start) / (long double)(CLOCKS_PER_SEC);
  cerr << (long double)t_t * 1000 << " ms ";
}
