#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
const int mod = 1e9 + 7;
int q, n, f;
map<int, int> d[maxn + 1];
int fac[maxn + 1], rev[maxn + 1];
int pow(int a, int p) {
  int ans = 1;
  while (p) {
    if (p & 1) {
      ans = (1ll * ans * a) % mod;
    }
    a = (1ll * a * a) % mod;
    p >>= 1;
  }
  return ans;
}
void init() {
  fac[0] = 1;
  rev[0] = 1;
  for (int i = 1; i <= maxn; i++) {
    fac[i] = (1ll * fac[i - 1] * i) % mod;
    rev[i] = pow(fac[i], mod - 2);
  }
}
int comb(int a, int b) {
  if (a == b) return 1;
  if (a < b) return 0;
  return (1ll * ((1ll * fac[a] * rev[b]) % mod) * rev[a - b]) % mod;
}
int dp(int n, int f) {
  if (f > n) return 0;
  if (f == n) return 1;
  if (f == 1) return n == 1;
  if (d[n].count(f)) return d[n][f];
  long long ans = comb(n - 1, f - 1);
  int i;
  for (i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      ans = ans - dp(n / i, f);
      if (ans < 0) ans += mod;
      if (i * i == n) break;
      ans = ans - dp(i, f);
      if (ans < 0) ans += mod;
    }
  }
  return d[n][f] = (int)(ans % mod);
}
int main() {
  init();
  int q;
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int n, f;
    scanf("%d%d", &n, &f);
    printf("%d\n", (dp(n, f) + mod) % mod);
  }
  return 0;
}
