#include <bits/stdc++.h>
using namespace std;
const long long N = 5000100;
vector<long long> vect(5000100), vect2(5000100);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  for (int i = 2; i < N; i++) {
    if (vect[i] == 0) {
      for (int j = i; j < N; j += i) {
        if (vect[j] == 0) vect[j] = i;
      }
    }
  }
  vect2[1] = 1;
  for (int i = 2; i < N; i++) {
    vect2[i] += vect2[i - 1];
    int j = i;
    while (j > 1) {
      j /= vect[j];
      vect2[i]++;
    }
  }
  long long t;
  cin >> t;
  while (t--) {
    long long a, b;
    cin >> a >> b;
    cout << vect2[a] - vect2[b] << "\n";
  }
  return 0;
}
