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