#include <bits/stdc++.h>
const int mod = 1000000007;
const long long INF = 9000000000000000000;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n = 5000000, q, a, b;
  vector<long long> cont(5000009, 0);
  for (int i = 2; i <= n; i++) {
    if (cont[i] == 0) {
      for (int j = i; j <= n; j += i) {
        int cur = j;
        while (cur % i == 0) {
          cur /= i;
          cont[j]++;
        }
      }
    }
    cont[i] += cont[i - 1];
  }
  scanf("%lld", &q);
  while (q--) {
    scanf("%lld %lld", &a, &b);
    long long ans = (cont[a] - cont[b]);
    printf("%lld\n", ans);
  }
  return 0;
}
