#include <bits/stdc++.h>
using namespace std;
int myRnd() { return abs(((rand() << 15) ^ rand())); }
int myRnd(int L, int R) {
  return abs(((rand() << 15) ^ rand())) % (R - L + 1) + L;
}
void Parr(int *arr, int L, int R) {
  for (int i = L; R >= i; i++) {
    printf("%d%c", arr[i], " \n"[i == R]);
  }
}
void Pvec(vector<int> v) {
  for (int i = 0; ((int)(v).size()) > i; i++) {
    printf("%d%c", v[i], " \n"[i == ((int)(v).size()) - 1]);
  }
}
void Sarr(int *arr, int L, int R) {
  for (int i = L; R >= i; i++) {
    scanf("%d", &(arr[i]));
    ;
  }
}
const int N = 76 + 6;
const int mod = 1000000000 + 7;
const long long INF = 1000000000000000007LL;
int a[N];
int u[N];
int p[N];
long long ppow(long long a, long long n) {
  if (n * log10(a) > 18.2)
    return INF;
  else {
    long long ret = 1;
    while (n--) ret *= a;
    return ret;
  }
}
long long pow_form[N][N];
void build2() {
  for (int i = 2; N > i; i++) {
    for (int j = 2; N > j; j++) {
      pow_form[i][j] = ppow(i, j);
    }
  }
}
int Rs[12] = {0, 0, 1000000001, 1000001, 31666, 3999, 1002, 377, 180, 102, 65};
long long solve(long long x) {
  if (x == 0) return 0;
  if (x == 1) return 1;
  long long ret = 1;
  for (int p = 2;; p++) {
    if ((1LL << p) > x) break;
    long long a = 2;
    if (p <= 10) {
      int L = 2, R = Rs[p];
      while (R - L != 1) {
        int mid = (L + R) >> 1;
        if (ppow(mid, p) <= x)
          L = mid;
        else
          R = mid;
      }
      a = L + 1;
    } else
      while (pow_form[a][p] <= x) ++a;
    --a;
    ret += u[p] * (a - 1);
  }
  return ret;
}
void build() {
  for (int i = 0; N > i; i++) {
    u[i] = -1;
  }
  for (int i = 2; N > i; i++) {
    if (p[i] == 0) {
      p[i] = 1;
      for (int j = i; N > j; j += i) {
        p[j] = 1;
        u[j] *= -1;
        if ((j / i) % i == 0) u[j] = 0;
      }
    }
  }
}
int main() {
  srand(time(NULL));
  build();
  build2();
  int q;
  scanf("%d", &(q));
  ;
  while (q--) {
    long long L, R;
    scanf("%lld %lld", &(L), &(R));
    ;
    printf("%lld\n", (solve(R) - solve(L - 1)) * 1LL);
    ;
  }
}
