#include <bits/stdc++.h>
using namespace std;
vector<long long> a;
inline char nc() {
  static char buf[10001], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 10000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline long long read() {
  register long long s = 0;
  register char c = nc();
  while (c < '0' || c > '9') c = nc();
  while (c >= '0' && c <= '9') s = (s << 1) + (s << 3) + c - 48, c = nc();
  return s;
}
inline void print(const long long &x) {
  if (x > 9LL) print(x / 10LL);
  putchar(x % 10LL + 48);
}
inline long long Sqrt(long long x) {
  long long l = 0, r = 1e9, res;
  while (l <= r) {
    long long mid = (l + r) >> 1LL;
    if (mid * mid <= x)
      res = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  return res;
}
void init() {
  for (long long i = 2; i <= 1000000; ++i) {
    double t = 1.0 * i * i * i;
    long long x = i * i * i;
    while (t < 2e18) {
      long long root = Sqrt(x);
      if (root * root != x) a.push_back(x);
      x *= i;
      t *= i;
    }
  }
  sort(a.begin(), a.end());
  unique(a.begin(), a.end());
}
int main() {
  init();
  long long Q = read();
  while (Q--) {
    long long l = read(), r = read();
    long long ans = Sqrt(r) - Sqrt(l - 1);
    ans +=
        upper_bound(a.begin(), a.end(), r) - lower_bound(a.begin(), a.end(), l);
    print(ans);
    puts("");
  }
}
