#include <bits/stdc++.h>
using namespace std;
const int N = 5e6;
long long P[N + 1], S[N + 1];
int main() {
  for (int i = 0; i <= N; ++i) P[i] = 0;
  for (int i = 2; i <= N; ++i)
    if (P[i] == 0)
      for (long long p = i; p <= N; p *= i)
        for (int k = p; k <= N; k += p) ++P[k];
  S[0] = 0;
  for (int i = 1; i <= N; ++i) S[i] = S[i - 1] + P[i];
  ios::sync_with_stdio(0);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int a, b;
    cin >> a >> b;
    cout << S[a] - S[b] << '\n';
  }
  return 0;
}
