#include <bits/stdc++.h>
using namespace std;
void zanj0() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
const long long int N = 5000005;
long long int lpf[N];
long long int numberOfFactors[N];
void pre() {
  for (long long int i = 0; i < N; i++) {
    lpf[i] = i;
    if (i % 2 == 0) lpf[i] = 2;
  }
  for (long long int i = 3; i * i < N; i += 2) {
    if (lpf[i] == i) {
      for (long long int j = i * i; j <= N; j += i) {
        lpf[j] = i;
      }
    }
  }
  for (long long int i = 2; i < N; i++) {
    numberOfFactors[i] += numberOfFactors[i / lpf[i]] + 1;
  }
  for (long long int i = 1; i < N; i++) {
    numberOfFactors[i] += numberOfFactors[i - 1];
  }
}
void solve() {
  long long int a, b;
  cin >> a >> b;
  long long int ret = 0;
  cout << numberOfFactors[a] - numberOfFactors[b] << "\n";
}
int main() {
  zanj0();
  pre();
  long long int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
