#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int N = 3e5 + 6;
int64_t d[6000000];
bool prime[6000000];
void seive() {
  for (int i = 2; i <= 5000000; i++) {
    if (!prime[i]) {
      d[i] = 1;
      for (int j = 2 * i; j <= 5000000; j += i) {
        int64_t p = j;
        while (p % i == 0) {
          d[j]++;
          p /= i;
        }
        prime[j] = true;
      }
    }
  }
  for (int i = 2; i <= 5000000; i++) d[i] += d[i - 1];
}
int main() {
  int64_t t;
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> t;
  seive();
  while (t--) {
    int64_t a, b;
    cin >> a >> b;
    cout << d[a] - d[b] << '\n';
  }
  return 0;
}
