#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e18;
long long q, l, r;
vector<long long> v;
long long g(long long x) {
  if (!x) return 0;
  return upper_bound(v.begin(), v.end(), x) - v.begin() + sqrt(x);
}
int main() {
  for (long long i = 2; i * i * i <= maxn; i++) {
    for (long long j = i * i; j <= maxn / i; j *= i) {
      long long temp = sqrt(j * i);
      if (temp * temp != j * i) {
        v.push_back(j * i);
      }
    }
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  scanf("%lld", &q);
  while (q--) {
    scanf("%lld %lld", &l, &r);
    printf("%lld\n", g(r) - g(l - 1));
  }
  return 0;
}
