#include <bits/stdc++.h>
using namespace std;
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;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  set<long long> se;
  long long a = 2;
  for (; a <= 1000000ll; a++) {
    long long re = a * a * a;
    while (true) {
      if (root(re) * root(re) != re) se.insert(re);
      if (re > (1e18) / (a + 0.0)) break;
      re *= a;
    }
  }
  vector<long long> vec;
  for (auto i : se) vec.push_back(i);
  int L;
  cin >> L;
  long long ans = 0;
  while (L--) {
    long long l, r;
    cin >> l >> r;
    long long lef, rig;
    long long ans = upper_bound(vec.begin(), vec.end(), r) -
                    lower_bound(vec.begin(), vec.end(), l) + (root(r)) -
                    (root(l - 1));
    cout << ans << '\n';
  }
}
