#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
const int M = 1000000007;
const double eps = 1e-9;
const double PI = acos(-1);
const int oo = 1000000000;
long long q, l, r;
vector<long long> v;
long long root(long long x) {
  long long lo = 1, hi = oo, md, best = 0;
  while (lo <= hi) {
    md = (lo + hi) / 2;
    if (md * md <= x) {
      best = md;
      lo = md + 1;
    } else
      hi = md - 1;
  }
  return best;
}
int main() {
  for (int i = 2; i <= 10 * N; ++i) {
    long long d = 1ll * i * i;
    double x = 1ll * i * i;
    for (int j = 0;; ++j) {
      x *= i;
      d *= i;
      if (x > 1e18) break;
      if (j % 2 == 0) {
        v.push_back(d);
      }
    }
  }
  for (int i = 0; i < v.size(); ++i) {
    long long d = root(v[i]);
    if (d * d == v[i]) {
      swap(v[i], v.back());
      v.pop_back();
      --i;
    }
  }
  sort((v).begin(), (v).end());
  v.resize(unique((v).begin(), (v).end()) - v.begin());
  cin >> q;
  while (q--) {
    scanf("%lld%lld", &l, &r);
    long long ans = upper_bound((v).begin(), (v).end(), r) -
                    lower_bound((v).begin(), (v).end(), l);
    ans += root(r) - root(l - 1);
    printf("%lld\n", ans);
  }
  return 0;
}
