#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  scanf("%d", &t);
  int n = 5000000;
  vector<int> e(n + 1, 1);
  vector<int> d(n + 1);
  e[0] = e[1] = 0;
  for (int i = 2; i * i <= n; ++i) {
    if (e[i] == 1 && i * 1ll * i <= n) {
      for (int j = i * i; j <= n; j += i) {
        e[j] = e[j / i] + 1;
      }
    }
  }
  for (int i = 2; i <= n; i++) {
    d[i] = d[i - 1] + e[i];
  }
  for (int i = 0; i < t; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d\n", d[a] - d[b]);
  }
  return 0;
}
