#include <bits/stdc++.h>
using namespace std;
long long spf[7000005];
long long pw[7000005];
long long dp[7000005];
void sieve() {
  spf[1] = 1;
  for (long long i = 2; i < 7000005; i++) spf[i] = i;
  for (long long i = 4; i < 7000005; i += 2) spf[i] = 2;
  for (long long i = 3; i * i < 7000005; i++) {
    if (spf[i] == i) {
      for (long long j = i * i; j < 7000005; j += i)
        if (spf[j] == j) spf[j] = i;
    }
  }
}
void getFactorization(long long x) {
  long long z = x;
  long long cnt = 0;
  while (x != 1) {
    x = x / spf[x];
    cnt++;
  }
  pw[z] = cnt;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  sieve();
  for (long long int i = 1; i < 7000005; i++) {
    getFactorization(i);
    dp[i] = dp[i - 1] + pw[i];
  }
  while (t--) {
    long long a, b;
    cin >> a >> b;
    cout << dp[a] - dp[b] << '\n';
  }
}
