#include <bits/stdc++.h>
using namespace std;
std::set<long long> S;
std::map<long long, long long> mp;
long long mx = 1e18 + 1;
std::set<long long>::iterator it;
void ini() {
  for (int k = 3; k <= 59; k++) {
    bool flag = true;
    for (long long i = 2;; i++) {
      long long pr = 1;
      for (long long j = 1; j <= k; j++) {
        if (pr > (mx / i)) {
          flag = false;
          break;
        }
        pr *= i;
      }
      if (!flag) break;
      S.insert(pr);
    }
  }
  std::vector<long long> del;
  for (it = S.begin(); it != S.end(); ++it) {
    long long x = (long long)sqrt(*it);
    if (x * x == *it) del.push_back(*it);
  }
  for (int k = 0; k < del.size(); k++) {
    S.erase(del[k]);
  }
  int in = 0;
  for (it = S.begin(); it != S.end(); ++it) {
    mp[*it] = ++in;
  }
}
long long count(long long x) {
  if (x == 0) return 0;
  if (x < 4) return 1;
  if (x < 8) return 2;
  long long s = mp[(*--S.upper_bound(x))];
  s += (long long)sqrt(x);
  return s;
}
int main() {
  int T;
  scanf("%d", &T);
  ini();
  while (T--) {
    long long x, y;
    scanf("%lld%lld", &x, &y);
    printf("%lld\n", count(y) - count(x - 1));
  }
}
