#include <bits/stdc++.h>
using namespace std;
template <typename T = int>
inline T read() {
  T val = 0, sign = 1;
  char ch;
  for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') sign = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) val = val * 10 + ch - '0';
  return sign * val;
}
double eps = 1e-8;
long long root(long long x) {
  long long l = 0, r = 1e9 + 1;
  while (l < r - 1) {
    long long m = l + (r - l) / 2;
    if (m * m > x)
      r = m;
    else
      l = m;
  }
  return l;
}
vector<long long> s;
int main() {
  s.push_back(1);
  for (long long i = 2; i <= 1e6; ++i) {
    long long tmp = i * i * i;
    while (tmp <= 1e18) {
      s.push_back(tmp);
      if (tmp > 1e18 / i) break;
      tmp *= i;
    }
  }
  sort(s.begin(), s.end());
  s.erase(unique(s.begin(), s.end()), s.end());
  vector<long long> fuck;
  for (auto &x : s) {
    long long sqt = root(x);
    if (sqt * sqt != x) {
      fuck.push_back(x);
    }
  }
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  for (int i = (1); i <= (q); i++) {
    long long l, r;
    cin >> l >> r;
    long long dist = distance(lower_bound(fuck.begin(), fuck.end(), l),
                              upper_bound(fuck.begin(), fuck.end(), r));
    long long x = root(r), y = root(l - 1);
    cout << dist + (x - y) << endl;
  }
  return 0;
}
