#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const long long MOD = 1e9 + 7;
long long fact[N];
long long invfact[N];
long long mod_pow(long long x, long long n) {
  long long res = 1;
  while (n) {
    if (n & 1) res = res * x % MOD;
    x = x * x % MOD;
    n >>= 1;
  }
  return res;
}
inline long long inv(long long x) { return mod_pow(x, MOD - 2); }
inline long long comb(long long n, long long r) {
  return (fact[n] * invfact[r]) % MOD * invfact[n - r] % MOD;
}
vector<int> factor[N];
map<int, long long> dp[N];
int rec(int f, int n) {
  if (f < n) return 0;
  if (dp[n].count(f)) return dp[n][f];
  long long &res = dp[n][f];
  res = comb(f - 1, n - 1);
  for (auto e : factor[f]) {
    res -= rec(e, n);
    if (res < 0) res += MOD;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  for (int i = 2; i < N; ++i) {
    for (int j = i * 2; j < N; j += i) factor[j].push_back(i);
  }
  fact[0] = 1;
  for (int i = (1); i < (int)(N); ++i) fact[i] = (fact[i - 1] * i) % MOD;
  for (int i = (0); i < (int)(N); ++i) invfact[i] = inv(fact[i]);
  int q;
  cin >> q;
  for (int i = (0); i < (int)(q); ++i) {
    int f, n;
    cin >> f >> n;
    if (n == 1)
      cout << (f == 1) << '\n';
    else
      cout << rec(f, n) << '\n';
  }
  return 0;
}
