#include <bits/stdc++.h>
using namespace std;
const int sz = 5000000 + 2;
vector<int> primes;
vector<bool> prime(sz, true);
int factor[sz];
void genFactor() {
  memset(factor, 0, sizeof factor);
  for (int x = 2; x <= sz; x++) {
    if (!factor[x]) {
      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() {
  genFactor();
  int t;
  scanf("%d", &t);
  while (t--) {
    int a, b;
    scanf("%d %d", &a, &b);
    cout << factor[a] - factor[b] << endl;
  }
}
