#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18 + 1e2;
set<long long> used;
vector<long long> nums, squares;
long long n;
void make() {
  used.insert(1);
  for (long long i = 2; i * i * i < inf; ++i) {
    long long now = i * i * i;
    while (now < inf) {
      used.insert(now);
      if (log2(now) + log2(i) > log2(inf)) break;
      now *= i;
    }
  }
  n = used.size();
  for (auto i : used) nums.push_back(i);
  squares.resize(n);
  long long current = 0;
  for (long long i = 0; i < n; ++i) {
    if ((long long)(sqrt(nums[i])) * (long long)(sqrt(nums[i])) == nums[i])
      ++current;
    squares[i] = current;
  }
}
long long get_ans(long long r) {
  long long left = -1, right = n - 1;
  while (right - left > 1) {
    long long mid = left + right >> 1;
    if (nums[mid] > r)
      right = mid;
    else
      left = mid;
  }
  if (left < 0) return 0;
  return (long long)((sqrt(r))) + left + 1 - squares[left];
}
void solve() {
  long long l, r;
  cin >> l >> r;
  cout << get_ans(r) - get_ans(l - 1) << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long q;
  cin >> q;
  make();
  for (long long i = 0; i < q; ++i) solve();
  return 0;
}
