#include <bits/stdc++.h>
using namespace std;
int t;
int sum[5100000];
int main() {
  ios::sync_with_stdio(0);
  for (int i = 2; i <= 5000000; ++i) {
    if (sum[i] == 0)
      for (int j = i; j <= 5000000; j += i) {
        int k = j;
        while (k % i == 0) {
          k /= i;
          sum[j]++;
        }
      }
  }
  for (int i = 2; i <= 5000000; ++i) sum[i] = sum[i - 1] + sum[i];
  int a, b;
  scanf("%d", &t);
  while (t--) {
    scanf("%d %d", &a, &b);
    printf("%d\n", sum[a] - sum[b]);
  }
}
