#include <bits/stdc++.h>
int64_t root(int64_t n);
bool is_square(int64_t n);
std::vector<int64_t> generate_powers();
int main() {
  std::ios_base::sync_with_stdio(false);
  int64_t Q;
  std::cin >> Q;
  auto powers = generate_powers();
  for (int i = 0; i < Q; ++i) {
    int64_t l, r;
    std::cin >> l >> r;
    int64_t result = std::upper_bound(powers.begin(), powers.end(), r) -
                     std::lower_bound(powers.begin(), powers.end(), l);
    result += root(r) - root(l - 1);
    std::cout << result << "\n";
  }
}
int64_t root(int64_t n) {
  int64_t l = 1, r = 1e9;
  while (l <= r) {
    int64_t mid = (l + r) / 2;
    int64_t mid_sqr = mid * mid;
    if (mid_sqr < n) {
      l = mid + 1;
    } else if (mid_sqr > n) {
      r = mid - 1;
    } else {
      return mid;
    }
  }
  return r;
}
bool is_square(int64_t n) {
  int64_t root_ = root(n);
  return root_ * root_ == n;
}
std::vector<int64_t> generate_powers() {
  int64_t M = 1e18;
  std::vector<int64_t> result = {1};
  for (int64_t i = 2; i <= 1e6; ++i) {
    for (int64_t j = i * i * i; j <= M; j *= i) {
      result.push_back(j);
      if (j > M / i) break;
    }
  }
  result.erase(std::remove_if(result.begin(), result.end(), is_square),
               result.end());
  std::sort(result.begin(), result.end());
  result.erase(std::unique(result.begin(), result.end()), result.end());
  return result;
}
