#include <bits/stdc++.h>
using namespace std;
bool square(long long g) {
  long long k = sqrt(g);
  return k * k == g;
}
int main() {
  int i, q, k;
  long long l, r, val;
  set<long long> s;
  for (i = 2; i <= 1000000; i++) {
    int op = 18.0 / log10(i);
    val = 1LL * i * i;
    for (k = 3; k <= op; k++) {
      val *= i;
      if (!square(val)) s.insert(val);
    }
  }
  vector<long long> v(s.begin(), s.end());
  cin >> q;
  for (i = 0; i < q; i++) {
    cin >> l >> r;
    long long a = floor(sqrtl(r));
    long long b = ceil(sqrtl(l));
    long long res =
        upper_bound(v.begin(), v.end(), r) - lower_bound(v.begin(), v.end(), l);
    long long res1 = a - b + 1;
    cout << res + res1 << endl;
  }
}
