#include <bits/stdc++.h>
using namespace std;
int t, n, f;
long long facto[100000 + 5], mobinverse[100000 + 5];
int mobius[100000 + 5];
vector<int> primes;
bool sieve[100000 + 5];
long long pangkat(long long a, long long b) {
  if (b == 0) return 1;
  if (b == 1) return a;
  long long temp = pangkat(a, b / 2);
  return (((temp * temp) % 1000000007) * pangkat(a, b % 2)) % 1000000007;
}
long long combi(long long a, long long b) {
  return (((facto[a] * mobinverse[a - b]) % 1000000007) * mobinverse[b]) %
         1000000007;
}
int main() {
  facto[0] = 1;
  for (int i = 1; i <= 100000; i++) {
    mobius[i] = 1;
  }
  for (int i = 2; i <= 100000; i++) {
    if (sieve[i]) continue;
    primes.push_back(i);
    for (int j = i; j <= 100000; j += i) {
      sieve[j] = true;
      mobius[j] *= -1;
    }
    sieve[i] = false;
    long long temp = (long long)i * i;
    for (long long j = temp; j <= 100000; j += temp) {
      mobius[j] = 0;
    }
  }
  mobinverse[0] = 1;
  for (int i = 1; i <= 100000; i++) {
    facto[i] = facto[i - 1] * i;
    facto[i] %= 1000000007;
    mobinverse[i] = pangkat(facto[i], 1000000007 - 2);
  }
  scanf("%d", &t);
  while (t--) {
    scanf("%d %d", &n, &f);
    if (f == 1) {
      if (n == 1)
        printf("1\n");
      else
        printf("0\n");
      continue;
    }
    int ctr = 1;
    long long res = 0;
    if (!sieve[n]) {
      printf("%lld\n", combi(n - 1, f - 1));
      continue;
    }
    while (ctr * ctr <= n) {
      if (n % ctr == 0 and n / ctr >= f) {
        res += mobius[ctr] * combi(n / ctr - 1, f - 1);
        if (res < 0)
          res += 1000000007;
        else
          res %= 1000000007;
      }
      if (n % ctr == 0 and ctr >= f and ctr * ctr != n) {
        res += mobius[n / ctr] * combi(ctr - 1, f - 1);
        if (res < 0)
          res += 1000000007;
        else
          res %= 1000000007;
      }
      ctr++;
    }
    printf("%lld\n", res);
  }
}
