#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> f(5000100, 0);
  vector<bool> usado(5000100, false);
  for (int i = 2; i < 5000100; i++) {
    if (!usado[i]) {
      long long t = i;
      while (t <= 5000100) {
        for (long long j = t; j < 5000100; j += t) {
          usado[j] = true;
          f[j]++;
        }
        t *= i;
      }
    }
  }
  for (int i = 1; i < 5000100; i++) f[i] += f[i - 1];
  int q, a, b;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d %d", &a, &b);
    printf("%d\n", f[a] - f[b]);
  }
  return 0;
}
