#include <bits/stdc++.h>
using namespace std;
long long int MOD = (long long int)1e9 + 7;
long long int pd[(int)5e6 + 5];
bool prime[(int)5e6 + 5];
int t, a, b;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  memset(prime, true, sizeof(prime));
  memset(pd, 0, sizeof(pd));
  for (int i = 2; i <= (int)5e6 + 5; i++) {
    if (!pd[i]) {
      for (int j = i; j <= (int)5e6 + 5; j += i) {
        a = j;
        while (a % i == 0) {
          a /= i;
          pd[j]++;
        }
      }
    }
  }
  for (int i = 2; i <= (int)5e6 + 5; i++) pd[i] += pd[i - 1];
  scanf("%d\n", &t);
  while (t--) {
    scanf("%d %d\n", &a, &b);
    printf("%lld\n", pd[a] - pd[b]);
  }
  return 0;
}
