#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
int mod = 1000000007;
db pie = 3.1415926535;
int spf[5000005];
int mm = 5000000;
int pre[5000005];
void help() {
  int i;
  for (i = 1; i <= mm; i++) {
    spf[i] = i;
  }
  for (i = 2; i <= mm; i += 2) {
    spf[i] = 2;
  }
  int j;
  for (i = 3; i * i <= mm; i += 2) {
    if (spf[i] == i) {
      for (j = i * i; j <= mm; j += i) {
        if (spf[j] == j) spf[j] = i;
      }
    }
  }
  pre[0] = 0;
  pre[1] = 0;
  for (i = 2; i <= mm; i++) {
    int m = i;
    int cnt = 0;
    while (m > 1) {
      cnt++;
      m = m / spf[m];
    }
    pre[i] = cnt;
    pre[i] += pre[i - 1];
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  help();
  while (t--) {
    int a, b;
    cin >> a >> b;
    int ans = pre[a] - pre[b];
    cout << ans << "\n";
  }
}
