#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 77, Mod = 1000000007;
int Fact[N], InvFact[N], q, Ca[N], T[N], Num;
vector<int> Div[N];
int Pow(int X, int Y) {
  if (Y == 0) {
    return (1);
  }
  int C = Pow(X, Y >> 1);
  C = (C * 1ll * C) % Mod;
  if (Y & 1) {
    C = (C * 1ll * X) % Mod;
  }
  return C;
}
int C(int X, int Y) {
  if (X < 0 || X > Y) {
    return 0;
  }
  return ((Fact[Y] * 1ll * InvFact[X] % Mod) * 1ll * InvFact[Y - X]) % Mod;
}
int F(int n, int f) {
  if (f > n) return 0;
  if (f == n) return 1;
  if (T[n] == Num) return Ca[n];
  T[n] = Num;
  int A = C(f - 1, n - 1);
  for (int x : Div[n]) {
    A = A - F(x, f);
    if (A < 0) A += Mod;
  }
  Ca[n] = A;
  return A;
}
void solve(int n, int f) {
  Num++;
  int A = F(n, f);
  printf("%d\n", A);
}
int main() {
  Fact[0] = InvFact[0] = 1;
  for (int i = 1; i < N; i++) {
    Fact[i] = (Fact[i - 1] * 1ll * i) % Mod;
  }
  InvFact[N - 1] = Pow(Fact[N - 1], Mod - 2);
  for (int i = N - 2; i > 0; i--) {
    InvFact[i] = (InvFact[i + 1] * 1ll * (i + 1)) % Mod;
  }
  for (int i = 1; i < N; i++) {
    for (int j = i + i; j < N; j += i) {
      Div[j].push_back(i);
    }
  }
  scanf("%d", &q);
  while (q--) {
    int f, n;
    scanf("%d %d", &n, &f);
    solve(n, f);
  }
  return 0;
}
