#include <bits/stdc++.h>
using namespace std;
long long fac[100001];
bool prime[100001];
int largest_p[100001];
int mu[100001];
int divisor_count[100001];
int divisors[100001][65];
long long modpow(long long b, long long e) {
  if (e == 0) {
    return 1;
  } else {
    long long x = modpow(b, e / 2);
    if (e % 2 == 0) {
      return x * x % 1000000007;
    } else {
      return x * x % 1000000007 * b % 1000000007;
    }
  }
}
long long modinv(long long x) { return modpow(x, 1000000007 - 2); }
int main() {
  fac[0] = 1;
  for (int i = 1; i < 100001; i++) {
    fac[i] = (fac[i - 1] * i) % 1000000007;
  }
  for (int i = 1; i < 100001; i++) {
    prime[i] = true;
    largest_p[i] = 1;
  }
  for (int i = 2; i < 100001; i++) {
    if (prime[i]) {
      largest_p[i] = i;
      for (int j = i; j < 100001; j += i) {
        largest_p[j] = max(largest_p[j], i);
        prime[j] = false;
      }
    }
  }
  mu[1] = 1;
  for (int i = 2; i < 100001; i++) {
    if (largest_p[i] == largest_p[i / largest_p[i]]) {
      mu[i] = 0;
    } else {
      mu[i] = -mu[i / largest_p[i]];
    }
  }
  memset(divisor_count, 0, sizeof divisor_count);
  for (int i = 1; i < 100001; i++) {
    if (mu[i] != 0) {
      for (int j = i; j < 100001; j += i) {
        divisors[j][divisor_count[j]++] = i;
      }
    }
  }
  int q;
  scanf("%d\n", &q);
  while (q-- > 0) {
    int n, f;
    scanf("%d %d\n", &n, &f);
    long long ans = 0;
    for (int i = 0; i < divisor_count[n]; i++) {
      int divisor = divisors[n][i];
      int m = n / divisor - 1;
      int k = f - 1;
      if (m >= k) {
        ans = (ans +
               mu[divisor] * fac[m] % 1000000007 * modinv(fac[m - k]) %
                   1000000007 * modinv(fac[k]) % 1000000007 +
               1000000007) %
              1000000007;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
