#include <bits/stdc++.h>
using namespace std;
int prime[5000005];
int freq[5000005];
void lama() {
  for (int i = 2; i < 5000001; i++) {
    if (prime[i] == false) {
      for (int j = i; j < 5000001; j += i) {
        int x = j;
        while (x % i == 0) {
          freq[j]++;
          x /= i;
        }
        prime[j] = true;
      }
    }
  }
}
long long Sum[5000005];
void acc_sum(int arr[], long long sum[]) {
  sum[0] = arr[0];
  for (int i = 1; i <= 5000000; i++) {
    sum[i] = sum[i - 1] + arr[i];
  }
}
int main() {
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  cout.tie(0);
  int test;
  cin >> test;
  int a, b;
  lama();
  for (int i = 2; i < 5000001; i++) {
    freq[i] += freq[i - 1];
  }
  while (test--) {
    cin >> a >> b;
    cout << freq[a] - freq[b] << "\n";
  }
  return 0;
}
