#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const long long MOD = 1e9 + 7;
int n, q, m;
int prime[MAXN], primeN;
int minPrimeCnt[MAXN], divisor[MAXN];
bool isPrime[MAXN];
void getDivisor(int n) {
  for (int i = 1; i <= n; i++) isPrime[i] = true;
  isPrime[1] = false;
  primeN = 0;
  divisor[1] = 1;
  for (int i = 2; i <= n; i++) {
    if (isPrime[i]) {
      prime[++primeN] = i;
      divisor[i] = 2;
      minPrimeCnt[i] = 2;
    }
    for (int j = 1; j <= primeN; j++) {
      int nxt = prime[j] * i;
      if (nxt > n) break;
      divisor[nxt] = divisor[i] * 2;
      minPrimeCnt[nxt] = 2;
      isPrime[nxt] = false;
      if (i % prime[j] == 0) {
        minPrimeCnt[nxt] = minPrimeCnt[i] + 1;
        divisor[nxt] = divisor[i] / minPrimeCnt[i] * minPrimeCnt[nxt];
        break;
      }
    }
  }
}
long long inv[MAXN];
long long getinv(long long a) {
  if (inv[a] != -1) return inv[a];
  inv[a] = (a == 1 ? 1 : (MOD - MOD / a) * getinv(MOD % a) % MOD);
  return inv[a];
}
long long f[MAXN], invf[MAXN];
long long c(int n, int m) {
  if (n < m) return 0;
  if (n == m)
    return 1;
  else
    return f[n] * invf[m] % MOD * invf[n - m] % MOD;
}
int di[MAXN][200], dn[MAXN];
void pre() {
  n = 1e5;
  getDivisor(n);
  for (int i = 1; i <= n; i++) inv[i] = -1;
  for (int i = 1; i <= n; i++) getinv(i);
  f[0] = invf[0] = 1;
  for (int i = 1; i <= n; i++) {
    f[i] = f[i - 1] * i % MOD;
    invf[i] = invf[i - 1] * inv[i] % MOD;
  }
  memset(dn, 0, sizeof(dn));
  memset(di, 0, sizeof(di));
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j += i) {
      di[j][++dn[j]] = i;
    }
  }
}
long long ans[MAXN];
int cnt[MAXN];
int factor[MAXN], fn;
int main() {
  pre();
  while (scanf("%d", &q) != EOF) {
    for (int iq = 1; iq <= q; iq++) {
      scanf("%d%d", &n, &m);
      for (int i = 1; i <= dn[n]; i++) cnt[di[n][i]] = 0;
      cnt[n] = 1;
      for (int i = 1; i <= dn[n] - 1; i++) cnt[di[n][i]] = -1;
      for (int i = dn[n] - 1; i > 0; i--) {
        int x = di[n][i];
        if (cnt[x] == 0) continue;
        for (int i = 1; i <= dn[x] - 1; i++) cnt[di[x][i]] += -cnt[x];
      }
      long long res = 0;
      for (int i = 1; i <= dn[n]; i++) {
        int x = di[n][i];
        res += cnt[x] * c(x - 1, m - 1) % MOD;
        if (res < 0) res += MOD;
        if (res >= MOD) res -= MOD;
      }
      printf("%I64d\n", res);
    }
  }
  return 0;
}
