#include <bits/stdc++.h>
using namespace std;
const int64_t N = 1e6 + 5;
const int64_t MAX = 1e18;
vector<int64_t> V;
set<int64_t> sq, s;
int64_t sqroot(int64_t n) {
  int64_t low = 0, high = n;
  while (low < high) {
    int64_t mid = low + (high - low + 1) / 2;
    if (mid <= n / mid)
      low = mid;
    else
      high = mid - 1;
  }
  return low;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (int64_t i = 2; i < N; i++) {
    sq.insert(i * i);
    if (sq.find(i) != sq.end()) continue;
    int64_t temp = i;
    while (i * i <= MAX / temp) {
      temp *= (i * i);
      s.insert(temp);
    }
  }
  for (auto x : s) V.push_back(x);
  int64_t q;
  cin >> q;
  while (q--) {
    int64_t l, r;
    cin >> l >> r;
    int64_t res = sqroot(r) - sqroot(l - 1);
    int64_t hi = (upper_bound(V.begin(), V.end(), r) - V.begin());
    int64_t lo = (lower_bound(V.begin(), V.end(), l) - V.begin());
    res += (hi - lo);
    cout << res << "\n";
  }
  return 0;
}
