#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9;
const long long INFLL = (long long)1e16;
const int MOD = (int)1e9 + 7;
const int maxn = (int)1e5 + 5;
template <typename T>
void out(T x) {
  cout << x << endl;
  exit(0);
}
bool bysec(const pair<int, int> &a, const pair<int, int> &b) {
  return a.second < b.second;
}
int q;
set<long long> s;
bool square(long long x) {
  long long rt = sqrtl(x);
  return rt * rt == x;
}
void solve(vector<long long> &v) {
  long long l, r;
  cin >> l >> r;
  int sq = floor(sqrtl(r)) - ceil(sqrtl(l)) + 1;
  int count =
      upper_bound(v.begin(), v.end(), r) - lower_bound(v.begin(), v.end(), l);
  cout << count + sq << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> q;
  for (int i = 2; i <= (int)1e6; i++) {
    long long cur = i;
    int ops = 18 / log10(i);
    for (int k = 2; k <= ops; k++) {
      cur *= i;
      if (!square(cur)) s.insert(cur);
    }
  }
  vector<long long> v(s.begin(), s.end());
  while (q--) solve(v);
  return 0;
}
