#include <bits/stdc++.h>
using namespace std;
template <typename TF>
void debug(ostream &out, TF const &f) {
  out << f << std::endl;
}
template <typename TF, typename... TR>
void debug(ostream &out, TF const &f, TR const &...rest) {
  out << f << " ";
  debug(out, rest...);
}
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vii = vector<pii>;
using vll = vector<ll>;
using vs = vector<string>;
const int DR[] = {-1, 0, 1, 0, -1, 1, 1, -1};
const int DC[] = {0, -1, 0, 1, -1, -1, 1, 1};
const double PI = acos(-1.0);
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = 1073741823;
const ll INFLL = 4e18;
const int MAX = 1e6;
const ll RMAX = 1e18;
map<ll, int> cnt;
inline bool is_sqr(ll x) {
  ll t = sqrt(x);
  return t * t == x;
}
void build() {
  for (ll now = 2; now <= MAX; now++) {
    ll x = now * now;
    while (!__builtin_mul_overflow(x, now, &x) && x <= RMAX) {
      if (!is_sqr(x)) cnt[x] = 1;
    }
  }
  ll sum = 0;
  for (auto it = cnt.rbegin(); it != cnt.rend(); it++) {
    sum += it->second;
    it->second = sum;
  }
  cnt[RMAX + 1] = 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  build();
  int TC;
  cin >> TC;
  while (TC--) {
    ll L, R;
    cin >> L >> R;
    ll ans = cnt.lower_bound(L)->second - cnt.upper_bound(R)->second;
    ll lo = ceil(sqrt(1.0L * L));
    ll hi = sqrt(1.0L * R);
    ans += hi - lo + 1;
    cout << ans << "\n";
  }
}
