#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
long long fact[100005];
int q, used[100005], dp[100005], deg[100005];
vector<int> divisors[100005];
int power(long long a, long long b) {
  if (!b) return 1;
  long long t = power(a, b / 2);
  if (b % 2)
    return (((t * t) % 1000000007) * a) % 1000000007;
  else
    return (t * t) % 1000000007;
}
int C(int x, int y) {
  if (y < 0 || y > x) return 0;
  if (!y) return 1;
  long long a = (fact[y] * fact[x - y]) % 1000000007;
  return ((fact[x] * (long long)deg[y]) % 1000000007 * (long long)deg[x - y]) %
         1000000007;
}
int memo(int x, int y) {
  if (y > x) return 0;
  if (x == y) return 1;
  if (used[x] == q) return dp[x];
  used[x] = q;
  int res = C(x - 1, y - 1);
  for (int i = 0; i < divisors[x].size(); i++) {
    res -= memo(x / divisors[x][i], y);
    if (res < 0) res += 1000000007;
    res %= 1000000007;
  }
  dp[x] = res;
  return res;
}
int main() {
  scanf("%d", &q);
  for (int i = 2; i <= 100000; i++) {
    int x = i;
    while (x <= 100000) {
      divisors[x].push_back(i);
      x += i;
    }
  }
  fact[0] = 1;
  for (int i = 1; i <= 100000; i++)
    fact[i] = (fact[i - 1] * (long long)i) % 1000000007,
    deg[i] = power(fact[i], 1000000007 - 2);
  while (q) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (y == 1 && x > 1) {
      puts("0");
      q--;
      continue;
    }
    printf("%d\n", memo(x, y));
    q--;
  }
}
