#include <bits/stdc++.h>
using namespace std;
vector<long long> v;
long long lim = 1e18;
long long poz(long long x) {
  return (upper_bound(v.begin(), v.end(), x) - v.begin() + (long long)sqrt(x));
}
int main() {
  for (long long i = 2; i * i * i <= lim; i++) {
    long long x = i * i;
    while (x <= lim / i) {
      x *= i;
      long long s = (long long)sqrt(x);
      if (s * s != x) v.push_back(x);
    }
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long l, r;
    cin >> l >> r;
    long long ans = poz(r) - poz(l - 1);
    cout << ans << endl;
  }
}
