#include <bits/stdc++.h>
using namespace std;
long long sqrti(long long n) {
  long long l = 1, r = min((double)n, 1e9), m, res;
  while (l <= r) {
    m = (l + r) / 2;
    if (m * m > n)
      r = m - 1;
    else {
      l = m + 1;
      res = m;
    }
  }
  return res;
}
int main() {
  vector<long long> v;
  for (long long i = 2; i < 1e6; ++i) {
    long long cur = i * i;
    while ((double)cur * i < 1e18) {
      cur *= i;
      long long z = sqrti(cur);
      if (z * z != cur) v.push_back(cur);
    }
  }
  sort(v.begin(), v.end());
  v.resize(unique(v.begin(), v.end()) - v.begin());
  int q;
  cin >> q;
  long long l, r;
  while (q--) {
    scanf("%lld%lld", &l, &r);
    int res =
        upper_bound(v.begin(), v.end(), r) - lower_bound(v.begin(), v.end(), l);
    long long A = sqrti(l);
    long long B = sqrti(r);
    if (A * A < l) ++A;
    res += B - A + 1;
    printf("%d\n", res);
  }
  return 0;
}
