#include <bits/stdc++.h>
using namespace std;
const int sz = 5000000 + 2;
vector<int> primes;
vector<bool> prime(sz, true);
void genPrime() {
  int n = sz;
  for (int i = 2; i <= n; i++) {
    if (prime[i]) {
      for (int j = i * 2; j <= n; j += i) {
        prime[j] = false;
      }
      primes.push_back(i);
    }
  }
}
int factor[sz];
void genFactor() {
  memset(factor, 0, sizeof factor);
  for (int x : primes) {
    for (int j = x; j <= sz; j += x) {
      int temp = j;
      while (temp % x == 0) factor[j]++, temp /= x;
    }
  }
  for (int i = 2; i <= sz; i++) factor[i] = factor[i] + factor[i - 1];
}
int main() {
  genPrime();
  genFactor();
  int t;
  scanf("%d", &t);
  while (t--) {
    int a, b;
    scanf("%d %d", &a, &b);
    cout << factor[a] - factor[b] << endl;
  }
}
