#include <bits/stdc++.h>
using namespace std;
const long long N = 5e6 + 2;
long long f[N];
long long spf[N];
long long pre[N];
void ini() {
  f[0] = 0;
  f[1] = 0;
  pre[0] = 0;
  pre[1] = 0;
  for (long long i = 2; i < N; i++) {
    f[i] = 1 + f[i / spf[i]];
    pre[i] = f[i] + pre[i - 1];
  }
  return;
}
void sieve() {
  spf[1] = 1;
  for (long long i = 2; i < N; i++) spf[i] = i;
  for (long long i = 4; i < N; i += 2) spf[i] = 2;
  for (long long i = 3; i * i < N; i++) {
    if (spf[i] == i) {
      for (long long j = i * i; j < N; j += i)
        if (spf[j] == j) spf[j] = i;
    }
  }
  ini();
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  sieve();
  long long t;
  cin >> t;
  while (t--) {
    long long a, b;
    cin >> a >> b;
    cout << pre[a] - pre[b] << '\n';
  }
  return 0;
}
