#include <bits/stdc++.h>
using namespace std;
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
int f[300005], inv[300005];
int bigmod(int a, int n) {
  if (n == 0) return 1;
  int ans = bigmod(a, n / 2);
  ans = (1LL * ans * ans) % 1000000007;
  if (n % 2) {
    ans = (1LL * ans * a) % 1000000007;
  }
  return ans;
}
void pre() {
  f[0] = 1;
  inv[0] = 1;
  for (int i = 1; i < 300005; i++) {
    f[i] = 1LL * f[i - 1] * i % 1000000007;
    inv[i] = bigmod(f[i], 1000000007 - 2);
  }
}
int C(int n, int r) {
  if (n < r) return 0;
  return 1LL * f[n] * inv[r] % 1000000007 * inv[n - r] % 1000000007;
}
unordered_map<int, int, custom_hash> mp;
vector<int> all[300005];
map<pair<int, int>, int> cc;
bool comp[300005];
int k;
int run(int n) {
  if (cc.count({n, k})) return cc[{n, k}];
  if (mp.count(n)) return mp[n];
  int ans = C(n - 1, k - 1);
  for (int u : all[n]) {
    if (n / u >= k) ans = (ans - run(n / u)) % 1000000007;
    ans = (ans + 1000000007) % 1000000007;
  }
  cc[{n, k}] = ans;
  return mp[n] = ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  for (int i = 2; i < 300005; i++) {
    {
      for (int j = i * 2; j < 300005; j += i) {
        comp[j] = 1;
        all[j].push_back(i);
      }
    }
  }
  pre();
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n >> k;
    if (k == 1) {
      cout << (n == 1) << '\n';
      continue;
    }
    mp.clear();
    cout << run(n) << '\n';
  }
}
