#include <bits/stdc++.h>
using namespace std;
const long long maxn = 5e6 + 100;
const long long mod = 1e9 + 7;
const long long inf = 1e18;
long long t, a, b, ps[maxn], p[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  for (long long i = 2; i < maxn; i++) {
    if (p[i] == 0) {
      p[i] = i;
      for (long long j = i * i; j < maxn; j += i) {
        p[j] = i;
      }
    }
  }
  for (long long i = 2; i < maxn; i++) {
    ps[i] = ps[i / p[i]] + 1;
  }
  for (long long i = 2; i < maxn; i++) {
    ps[i] += ps[i - 1];
  }
  cin >> t;
  while (t--) {
    cin >> b >> a;
    cout << ps[b] - ps[a] << '\n';
  }
  return 0;
}
