#include <bits/stdc++.h>
using namespace std;
long long int m, n, f, h[200000], fakt[200000] = {1};
vector<int> v[200000];
long long int fe(long long int m, long long int n) {
  if (!n) return 1;
  long long int t = fe(m, n / 2);
  t = t * t % 1000000007LL;
  if (n & 1) t = t * m % 1000000007LL;
  return t;
}
long long int comb(long long int m, long long int n) {
  return fakt[m] * fe(fakt[n], 1000000007LL - 2) % 1000000007LL *
         fe(fakt[m - n], 1000000007LL - 2) % 1000000007LL;
}
long long int find(long long int n) { return comb(n - 1, f - 1); }
long long int rec(int ind, long long int carp, int s) {
  if (n / carp < f) return 0;
  if (ind == v[n].size()) {
    if (s & 1)
      return (-find(n / carp) + 1000000007LL) % 1000000007LL;
    else
      return find(n / carp);
  }
  return (rec(ind + 1, carp, s) + rec(ind + 1, carp * v[n][ind], s + 1)) %
         1000000007LL;
}
int main() {
  ios_base::sync_with_stdio(false);
  for (int i = 2; i <= 100005; i++)
    if (!h[i]) {
      for (int j = 2 * i; j <= 100005; j += i) {
        v[j].push_back(i);
        h[j] = 1;
      }
    }
  for (int i = 1; i <= 100005; i++) fakt[i] = fakt[i - 1] * i % 1000000007LL;
  cin >> m;
  while (m--) {
    cin >> n >> f;
    if (f == 1 and n != 1)
      cout << 0 << endl;
    else if (f == 1)
      cout << 1 << endl;
    else
      cout << rec(0, 1, 0) << endl;
  }
}
