#include <bits/stdc++.h>
using namespace std;
set<long long> Set;
vector<long long> val;
void PreCal(long long lim) {
  long long halfLim = pow(lim, 1 / 3.0);
  for (long long i = 2; i <= halfLim; ++i) {
    long long T = sqrt(i);
    if (T * T == i) continue;
    long long L = log(1e18) / log(i);
    T = i * i;
    for (long long p = 3, v = i * i * i; p <= L and v <= 1e18 and v > 0;
         v *= T, p += 2)
      Set.insert(v);
  }
  for (auto it : Set) val.push_back(it);
}
long long floorSqrt(long long x) {
  long long ret = sqrt(x);
  if (ret * ret > x) ret--;
  return ret;
}
int main() {
  PreCal(1e18);
  long long q, l, r;
  scanf("%lld", &q);
  while (q--) {
    scanf("%lld%lld", &l, &r);
    long long pSqr = floorSqrt(r) - floorSqrt(l - 1);
    long long Ans = upper_bound(val.begin(), val.end(), r) -
                    lower_bound(val.begin(), val.end(), l);
    printf("%lld\n", pSqr + Ans);
  }
  return 0;
}
