#include <bits/stdc++.h>
using std::endl;
using std::lower_bound;
using std::set;
using std::upper_bound;
static set<int_fast64_t> powers;
static int_fast64_t spowers[2000000];
static int spowers_sz;
template <class T>
static inline T sq(T x) {
  return x * x;
}
static inline int_fast64_t floorSqrt(const int_fast64_t num) {
  int_fast64_t approx = sqrt((long double)num);
  while (sq(approx) < num) ++approx;
  while (sq(approx) > num) --approx;
  return approx;
}
static inline int_fast64_t ceilSqrt(const int_fast64_t num) {
  const int_fast64_t floor = floorSqrt(num);
  return (sq(floor) == num ? floor : floor + 1);
}
static inline int_fast64_t exactSqrt(const int_fast64_t num) {
  const int_fast64_t floor = floorSqrt(num);
  return (sq(floor) == num ? floor : -1);
}
static inline int countThem(const int_fast64_t L, const int_fast64_t R) {
  int cnt = upper_bound(spowers, spowers + spowers_sz, R) -
            lower_bound(spowers, spowers + spowers_sz, L);
  const int_fast64_t leftSqrt = ceilSqrt(L);
  const int_fast64_t rightSqrt = floorSqrt(R);
  const int_fast64_t squaresCount = (rightSqrt - leftSqrt + 1);
  if (squaresCount > 0) cnt += squaresCount;
  return cnt;
}
int main(void) {
  using std::cin;
  using std::cout;
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  for (int_fast64_t A = 2; true; ++A) {
    int_fast64_t pwr = A;
    pwr *= A;
    if (pwr > ((int_fast64_t)1e18)) break;
    pwr *= A;
    if (pwr > ((int_fast64_t)1e18)) break;
    const int_fast64_t pwrLim = (((int_fast64_t)1e18) + A) / A;
    for (int_fast64_t P = 3; true; ++P, pwr *= A) {
      if (exactSqrt(pwr) < 0) {
        powers.insert(pwr);
      }
      if (pwr > pwrLim) break;
    }
  }
  for (const auto& pwr : powers) {
    spowers[spowers_sz++] = pwr;
  }
  assert(spowers_sz == (int)powers.size());
  int Q;
  cin >> Q;
  for (int ii = 0; ii < Q; ++ii) {
    int_fast64_t L, R;
    cin >> L >> R;
    cout << countThem(L, R) << '\n';
  }
  cout.flush();
  return 0;
}
