#include <bits/stdc++.h>
using namespace std;
const long long N = (long long)1e18;
long long square_root(long long x) {
  long long low = 0, high = sqrt(x) + 20, mid;
  while (low < high) {
    mid = (low + high + 1) >> 1;
    if (mid * mid <= x) {
      low = mid;
    } else {
      high = mid - 1;
    }
  }
  return low;
}
inline long long solve(long long l, long long r, vector<long long> &all) {
  long long ret = square_root(r) - square_root(l - 1);
  int first = (int)(--lower_bound(all.begin(), all.end(), l) - all.begin());
  int last = (int)(--upper_bound(all.begin(), all.end(), r) - all.begin());
  return ret + max(0, last - first);
}
long long power(long long x, long long e) {
  long double ret = 1;
  for (int i = 0; i < e; i++) {
    ret *= x;
    if (ret > N) {
      return N + 1;
    }
  }
  return (long long)ret;
}
int main() {
  vector<long long> almost_all, all;
  for (int p = 3; p <= 62; p++) {
    for (long long i = 1, j = -1; (j = power(i, p)) <= N; i++) {
      almost_all.push_back(j);
    }
  }
  sort(almost_all.begin(), almost_all.end());
  almost_all.erase(unique(almost_all.begin(), almost_all.end()),
                   almost_all.end());
  for (long long &x : almost_all) {
    long long y = square_root(x);
    if (y * y == x) {
      continue;
    }
    all.push_back(x);
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    long long l, r;
    scanf("%lld %lld", &l, &r);
    long long ans = solve(l, r, all);
    printf("%lld\n", ans);
  }
  return 0;
}
