#include <bits/stdc++.h>
const double EPS = 1e-24;
const long long int MOD = 1000000007ll;
const double PI = 3.14159265359;
int INF = 2147483645;
template <class T>
T Max2(T a, T b) {
  return a < b ? b : a;
}
template <class T>
T Min2(T a, T b) {
  return a < b ? a : b;
}
template <class T>
T Max3(T a, T b, T c) {
  return Max2(Max2(a, b), c);
}
template <class T>
T Min3(T a, T b, T c) {
  return Min2(Min2(a, b), c);
}
template <class T>
T Max4(T a, T b, T c, T d) {
  return Max2(Max2(a, b), Max2(c, d));
}
template <class T>
T Min4(T a, T b, T c, T d) {
  return Min2(Min2(a, b), Max2(c, d));
}
using namespace std;
long long int q, f, n;
long long int ans;
long long int fact[100010];
long long int invfact[100010];
vector<long long int> factors[100010];
bool isp[100010];
long long int powermod(long long int _a, long long int _b, long long int _m) {
  long long int _ret = 1;
  while (_b) {
    if (_b % 2 == 1) _ret = (_ret * _a) % _m;
    _b /= 2;
    _a = (_a * _a) % _m;
  }
  return _ret;
}
long long int solve(long long int n, long long int r) {
  if (n < r) return 0;
  long long int ret = fact[n];
  ret = (ret * invfact[r]) % MOD;
  ret = (ret * invfact[n - r]) % MOD;
  return ret;
}
long long int dfs(long long int s, long long int v, long long int i) {
  if (i == factors[v].size()) {
    if (factors[s].size() % 2 == 0)
      return solve(f / s - 1, n - 1);
    else
      return -solve(f / s - 1, n - 1);
  } else
    return (dfs(s, v, i + 1) + dfs(s * factors[v][i], v, i + 1)) % MOD;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  fact[0] = 1;
  for (int i = 1; i <= 100001; i++) fact[i] = (fact[i - 1] * i) % MOD;
  invfact[0] = invfact[1] = 1;
  for (int i = 2; i <= 100001; i++)
    invfact[i] = (invfact[i - 1] * powermod(i, MOD - 2, MOD)) % MOD;
  for (int i = 2; i <= 100001; i++) isp[i] = true;
  for (int i = 2; i <= 100001; i++) {
    if (isp[i]) {
      factors[i].push_back(i);
      for (int j = i + i; j <= 100001; j += i)
        isp[j] = false, factors[j].push_back(i);
    }
  }
  cin >> q;
  while (q--) {
    cin >> f >> n;
    cout << (dfs(1, f, 0) + MOD) % MOD << "\n";
  }
  return 0;
}
