#include <bits/stdc++.h>
using namespace std;
const long long LIM = 1e18;
long long root(long long x) {
  long long L = 0LL, R = 1e9 + 7;
  while (L < R - 1) {
    long long mid = (L + R) >> 1LL;
    if (mid * mid <= x)
      L = mid;
    else
      R = mid;
  }
  return L;
}
int main() {
  set<long long> s;
  for (long long i = 2; i <= 1e6; i++) {
    for (long long j = i * i * i; j <= LIM; j *= i) {
      long long val = sqrt(j);
      if (val * val != j) s.insert(j);
      if (j > LIM / i) break;
    }
  }
  vector<long long> v(s.begin(), s.end());
  int t;
  scanf("%d", &t);
  while (t--) {
    long long L, R;
    scanf("%lld %lld", &L, &R);
    long long ans =
        upper_bound(v.begin(), v.end(), R) - lower_bound(v.begin(), v.end(), L);
    ans += root(R) - root(L - 1);
    printf("%lld\n", ans);
  }
  return 0;
}
