#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const int mod = 1e9 + 7;
const int MOD = 1e9 + 7;
long long fact[MAXN];
long long inv_fact[MAXN];
long long nchoosek(int n, int k) {
  long long ans = fact[n] * inv_fact[n - k];
  ans %= MOD;
  ans = ans * inv_fact[k];
  ans %= MOD;
  return ans;
}
long long exp(long long base, long long exponent) {
  if (exponent == 0) return 1;
  if (exponent & 1) {
    long long ans = base * exp(base, exponent - 1);
    ans %= MOD;
    return ans;
  }
  long long ans = exp(base, exponent / 2);
  ans = ans * ans;
  ans %= MOD;
  return ans;
}
void gen() {
  fact[0] = inv_fact[0] = 1;
  for (int i = 1; i < MAXN; i++) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= MOD;
    inv_fact[i] = exp(fact[i], MOD - 2);
  }
}
vector<int> divisors[MAXN];
bool composite[MAXN];
int mobius[MAXN];
int prime_count[MAXN];
void sieve() {
  for (int i = 2; i < MAXN; i++) mobius[i] = 1;
  for (int i = 2; i < MAXN; i++) {
    if (composite[i]) continue;
    prime_count[i] = 1;
    for (int j = i + i; j < MAXN; j += i) {
      composite[j] = true;
      if (j % (1LL * i * i) == 0) mobius[j] = 0;
      prime_count[j]++;
    }
  }
  for (int i = 2; i < MAXN; i++) {
    if (!mobius[i]) continue;
    if (prime_count[i] & 1) {
      mobius[i] = -1;
    } else {
      mobius[i] = 1;
    }
  }
  for (int i = 2; i < MAXN; i++) {
    for (int j = i; j < MAXN; j += i) divisors[j].push_back(i);
  }
}
int main() {
  ios::sync_with_stdio(0);
  gen();
  sieve();
  int q;
  cin >> q;
  while (q--) {
    int total, buckets;
    cin >> total >> buckets;
    if (buckets == 1) {
      if (total == 1)
        cout << 1 << endl;
      else
        cout << 0 << endl;
      continue;
    }
    if (total < buckets) {
      cout << 0 << endl;
      continue;
    }
    long long ans = nchoosek(total - 1, buckets - 1);
    for (int i = 0; i < divisors[total].size(); i++) {
      int left = total / divisors[total][i];
      int current = divisors[total][i];
      if (buckets > left) continue;
      if (left == 1) continue;
      ans += mobius[current] * nchoosek(left - 1, buckets - 1);
      ans += mod;
      ans %= mod;
    }
    cout << ans << endl;
  }
}
