#include <bits/stdc++.h>
using namespace std;
vector<long long> cand;
long long sqfob(long long x) {
  long long l = 0, r = 1e9 + 1;
  while (l < r - 1) {
    long long m = (l + r) / 2;
    if (m * m > x)
      r = m;
    else
      l = m;
  }
  return l;
}
void solve(long long l, long long r) {
  long long res = 0;
  res += upper_bound(cand.begin(), cand.end(), r) -
         lower_bound(cand.begin(), cand.end(), l);
  res += sqfob(r) - sqfob(l - 1);
  printf("%lld\n", res);
  return;
}
void precalc() {
  long long U = 1e18;
  vector<long long> _cand = {1};
  for (long long i = 2; i <= 1e6; i++) {
    for (long long x = i * i * i; x <= U; x *= i) {
      _cand.push_back(x);
      if (x > U / i) break;
    }
  }
  sort(_cand.begin(), _cand.end());
  _cand.erase(unique(_cand.begin(), _cand.end()), _cand.end());
  for (const long long& u : _cand) {
    long long x = sqfob(u);
    if (x * x == u) continue;
    cand.push_back(u);
  }
  return;
}
int main(int argc, char** argv) {
  precalc();
  long long l, r;
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%lld %lld", &l, &r);
    solve(l, r);
  }
  return 0;
}
