#include <bits/stdc++.h>
using namespace std;
int resheto[3000];
int prime[1000];
long long A[5000100], B[5000100];
int main() {
  int i = 2, j, k = 1;
  prime[0] = 2;
  while (i < 2300) {
    for (j = i * i; j < 2300; j += i) resheto[j] = true;
    i++;
    while (resheto[i]) i++;
    prime[k++] = i;
  }
  A[1] = 0;
  B[1] = 0;
  int sum = 0, l;
  for (i = 2; i <= 5000000; i++) {
    l = i;
    for (j = 0; j < k && prime[j] * prime[j] <= i; j++) {
      if (i % prime[j] == 0) {
        B[i] += B[l / prime[j]] + B[prime[j]];
        break;
      }
    }
    if (i < prime[j] * prime[j]) B[i] = 1;
    A[i] = A[i - 1] + B[i];
    sum = 0;
  }
  int t, a, b;
  scanf("%d", &t);
  for (i = 0; i < t; i++) {
    scanf("%d%d", &a, &b);
    printf("%d\n", A[a] - A[b]);
  }
  return 0;
}
