#include <bits/stdc++.h>
using namespace std;
int q, a, b, snt[5000100], dp[5000100];
long long calc(long long x) {
  long long cnt = 0;
  while (x > 1) {
    x /= snt[x];
    cnt++;
  }
  return cnt;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> q;
  for (int i = 1; i <= 5000000; i++) snt[i] = i;
  for (int i = 2; i <= 5000000; i++) {
    if (snt[i] == i) {
      for (int j = 2; j <= 5000000 / i; j++) snt[i * j] = i;
    }
  }
  for (int i = 2; i <= 5000000; i++) dp[i] = dp[i - 1] + calc(i);
  while (q--) {
    cin >> a >> b;
    cout << dp[a] - dp[b] << "\n";
  }
  return 0;
}
