#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1};
int kx8[] = {1, 1, 2, 2, -1, -1, -2, -2};
int ky8[] = {2, -2, 1, -1, 2, -2, 1, -1};
long long bigmod(long long a, long long b, long long c) {
  if (b == 0) return 1 % c;
  long long x = bigmod(a, b / 2, c);
  x = (x * x) % c;
  if (b % 2 == 1) x = (x * a) % c;
  return x;
}
long long mod_inverse(long long a, long long mod) {
  return bigmod(a, mod - 2, mod);
}
const int M = 500005;
long long squareroot(long long x) {
  long long c = sqrt(x);
  if ((c + 1) * (c + 1) <= x) return c + 1;
  return c;
}
map<long long, int> mp;
vector<long long> vec;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (long long i = 2;; i++) {
    long double d = i;
    long double res = d * d * d;
    if (res > 1e18) break;
    long long now = i * i * i;
    long long ret = squareroot(now);
    if (ret * ret == now) continue;
    vec.push_back(now);
    mp[now] = 1;
  }
  for (long long j = 2;; j++) {
    long double d = j;
    long double res = d * d * d * d;
    long long now = j * j * j * j;
    if (now > 1e18) break;
    for (long long i = 5; i <= 62; i += 1) {
      res *= d;
      if (res > 1e18) break;
      now *= j;
      long long ret = squareroot(now);
      if (ret * ret == now) continue;
      if (mp.count(now)) continue;
      vec.push_back(now);
      mp[now] = 1;
    }
  }
  vec.push_back(2e18);
  sort(vec.begin(), vec.end());
  int q;
  cin >> q;
  while (q--) {
    long long l, r;
    cin >> l >> r;
    long long res = squareroot(r) - squareroot(l - 1);
    long long tot = upper_bound(vec.begin(), vec.end(), r) -
                    upper_bound(vec.begin(), vec.end(), l - 1);
    res += tot;
    cout << res << "\n";
  }
  return 0;
}
