#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
long long int arr[1000009], brr[1000009], crr[67];
std::vector<long long int> v[1000009], v1[70];
long long int solve(long long int l, long long int r, long long int bit) {
  long long int lo = 2, hi = crr[bit];
  long long int mn = r + 1;
  long long int mx = l - 1;
  while (lo <= hi) {
    long long int mi = (lo + hi) / 2;
    long long int val = 1;
    if (bit <= 3) {
      for (int i = 1; i <= bit && val <= r; i++) val *= mi;
    } else
      val = v1[bit][mi - 2];
    if (val > r)
      hi = mi - 1;
    else if (val >= l)
      hi = mi - 1, mn = mi;
    else
      lo = mi + 1;
  }
  lo = 2, hi = crr[bit];
  while (lo <= hi) {
    long long int mi = (lo + hi) / 2;
    long long int val = 1;
    if (bit <= 3) {
      for (int i = 1; i <= bit; i++) val *= mi;
    } else
      val = v1[bit][mi - 2];
    if (val > r)
      hi = mi - 1;
    else if (val >= l)
      lo = mi + 1, mx = mi;
    else
      lo = mi + 1;
  }
  long long int sol = max(mx - mn + 1 - brr[bit], 0LL);
  for (int j = 0; j < v[bit].size(); j++) brr[v[bit][j]] += sol;
  return sol;
}
void calculate() {
  long long int lst = 1e18;
  for (long long int i = 2; i < 60; i++) {
    long long int lo = 2, hi = 1e18;
    while (lo <= hi) {
      long long int mi = (lo + hi) / 2;
      long long int val = 1;
      for (long long int j = 1; j <= i && val <= lst; j++) {
        long long int a = val * mi;
        if (a < 0 || a > lst || (a / val) != mi || a % val)
          val = lst + 1;
        else
          val *= mi;
      }
      if (val <= lst)
        lo = mi + 1, crr[i] = mi;
      else
        hi = mi - 1;
    }
  }
}
void calculate1() {
  for (long long int i = 4; i <= 59; i++) {
    for (long long int j = 2; j <= crr[i]; j++) {
      long long int val = 1;
      for (long long int k = 1; k <= i; k++) val *= j;
      v1[i].push_back(val);
    }
  }
}
int main() {
  int test_case = 1;
  for (int cs = 1; cs <= test_case; cs++) {
    for (int i = 2; i <= 60; i++) {
      for (int j = i; j <= 60; j += i) v[j].push_back(i);
    }
    calculate();
    calculate1();
    long long int q;
    scanf("%lld", &q);
    while (q--) {
      long long int l, r;
      scanf("%lld %lld", &l, &r);
      long long int ans = 0;
      if (l == r && l == 1) {
        printf("1\n");
        continue;
      }
      if (l == 1) ans++, l++;
      for (int i = 59; i >= 2; i--) {
        ans += solve(l, r, i);
        brr[i] = 0;
      }
      printf("%lld\n", ans);
    }
  }
  return 0;
}
