#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 10;
const int MOD = 1000000007;
map<pair<long long, long long>, long long> dp;
long long A[MAX], B[MAX];
long long Qmod(long long x, long long n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1LL) res = res * x % MOD;
    x = x * x % MOD;
    n >>= 1LL;
  }
  return res;
}
void init() {
  A[0] = 1;
  B[0] = 1;
  for (int i = 1; i < MAX; i++) {
    A[i] = (A[i - 1] * i) % MOD;
    B[i] = Qmod(A[i], (long long)(MOD - 2));
  }
}
long long dfs(long long n, long long f) {
  if (dp.find(make_pair(n, f)) != dp.end()) return dp[make_pair(n, f)];
  if (n < f) return 0;
  if (f == 1) return n == 1 ? 1 : 0;
  long long t = ((A[n - 1] * B[f - 1]) % MOD * B[n - f]) % MOD;
  long long i;
  for (i = 2; i * i < n; i++) {
    if (n % i == 0) {
      t = (t - dfs(n / i, f) - dfs(i, f)) % MOD;
    }
  }
  if (i * i == n) t = (t - dfs(n / i, f)) % MOD;
  return dp[make_pair(n, f)] = t;
}
int main() {
  int cas;
  long long n, f;
  dp.clear();
  init();
  scanf("%d", &cas);
  for (int i = 0; i < cas; ++i) {
    scanf("%I64d %I64d", &n, &f);
    printf("%I64d\n", (dfs(n, f) + MOD) % MOD);
  }
  return 0;
}
