#include <bits/stdc++.h>
using namespace std;
vector<long long> cand;
vector<long long> _cand = {1}, see;
long long root(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, r;
  cin >> l >> r;
  long long ans = upper_bound((cand).begin(), (cand).end(), r) -
                  lower_bound((cand).begin(), (cand).end(), l);
  ans += root(r) - root(l - 1);
  printf("%lld\n", ans);
}
void precalc() {
  long long U = 1e18;
  for (long long i = 2; i <= 1e6; i++)
    for (long long curr = i * i * i; curr <= U; curr *= i) {
      _cand.push_back(curr);
      if (curr > 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 = root(u);
    if (x * x == u) continue;
    cand.push_back(u);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  precalc();
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
