#include <bits/stdc++.h>
using namespace std;
double PI = acos(-1);
double EPS = 1e-7;
int INF = 1000000000;
int MOD = 1000000007;
int MAXINT = 2147483647;
long long INFLL = 1000000000000000000LL;
long long MAXLL = 9223372036854775807LL;
int mx[8] = {-1, 1, 0, 0, -1, -1, 1, 1};
int my[8] = {0, 0, -1, 1, -1, 1, -1, 1};
long long inv[400005];
long long fac[400005];
long long mod = 1000000007;
int num[400005];
int prime[400005];
int ignored[400005];
void sieve() {
  for (int(x) = (2); (x) <= (100000); (x)++) {
    if (!prime[x]) {
      num[x] = 1;
      for (int y = 2; y * x <= 100000; y++) {
        int d = y * x;
        prime[d] = 1;
        int in = 0;
        while (d % x == 0) {
          in++;
          num[y * x]++;
          d /= x;
        }
        if (in > 1) ignored[y * x] = 1;
      }
    }
  }
}
inline long long ipow(long long base, int exp) {
  long long result = 1;
  while (exp) {
    if (exp & 1) result *= base;
    exp >>= 1;
    base *= base;
    result %= mod;
    base %= mod;
  }
  return result;
}
long long comb(int n, int k) {
  if (n < k) return 0;
  return ((fac[n] * inv[k]) % mod * inv[n - k]) % mod;
}
int main() {
  inv[0] = 1;
  fac[0] = 1;
  inv[1] = 1;
  fac[1] = 1;
  for (int(a) = (2); (a) <= (400000); (a)++) {
    inv[a] = (inv[a - 1] * ipow(a, mod - 2)) % mod;
    fac[a] = (fac[a - 1] * (long long)a) % mod;
  }
  sieve();
  int q;
  scanf("%d", &q);
  while (q--) {
    int n, f;
    scanf("%d%d", &n, &f);
    long long ans = 0;
    for (int x = 1; x * x <= n; x++) {
      if (n % x == 0) {
        int y = n / x;
        if (!ignored[x]) {
          if (num[x] % 2 == 1)
            ans += (mod - comb(y - 1, f - 1));
          else
            ans += (comb(y - 1, f - 1));
        }
        ans %= mod;
        if (x != y) {
          if (!ignored[y]) {
            if (num[y] % 2 == 1)
              ans += (mod - comb(x - 1, f - 1));
            else
              ans += (comb(x - 1, f - 1));
          }
          ans %= mod;
        }
      }
    }
    printf("%I64d\n", ans);
  }
}
