#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9;
const double PI = 2 * acos(0.0);
const double eps = 1e-15;
const int NPOS = -1;
const int MAX = 1000;
bool detectOverFlow(const long long& a, const long long& b) {
  long long x = a * b;
  if (x / a != b) return true;
  return false;
}
long long sqrt(long long a) {
  long long lo = 0, hi = 1e9 + 5;
  while (lo < hi - 1) {
    long long mid = (hi + lo) >> 1;
    if (mid * mid > a)
      hi = mid;
    else
      lo = mid;
  }
  return lo;
}
vector<long long> v;
void powerNumbers() {
  for (long long i = 2; i < 1000005; i++) {
    long long j = i * i;
    while (1.0 * j * i < 1e18 + 55) {
      j *= i;
      long long s = sqrt(j);
      if (s * s != j) v.push_back(j);
    }
  }
  sort(((v).begin()), ((v).end()));
  (v).resize(unique(((v).begin()), ((v).end())) - (v).begin());
}
int countSquares(long long a, long long b) {
  return ((sqrt(b)) - (sqrt(a - 1)));
}
int n;
long long l, r;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  powerNumbers();
  cin >> n;
  while (n--) {
    cin >> l >> r;
    int res = countSquares(l, r);
    res += upper_bound(((v).begin()), ((v).end()), r) -
           lower_bound(((v).begin()), ((v).end()), l);
    cout << res << '\n';
  }
  return 0;
}
