#include <bits/stdc++.h>
using namespace std;
const long long num = 5000000;
vector<long long> spf(num + 1), sum(num + 1);
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (long long i = 0; i <= num; i++) spf[i] = i;
  for (long long i = 2; i * i <= num; i++) {
    if (spf[i] == i) {
      for (long long j = i * i; j <= num; j += i) {
        if (spf[j] == j) spf[j] = i;
      }
    }
  }
  sum[1] = sum[0] = 0;
  for (long long i = 2; i <= num; i++) {
    long long x = i;
    long long count = 0, p;
    while (x > 1) {
      p = spf[x];
      x = (x / p);
      count++;
    }
    sum[i] = sum[i - 1] + count;
  }
  long long t;
  cin >> t;
  while (t--) {
    long long a, b;
    cin >> a >> b;
    long long res = sum[a] - sum[b];
    cout << res << "\n";
  }
  return 0;
}
