#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
using ll = long long int;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using mii = map<int, int>;
using pii = pair<int, int>;
const int inf = 1e9;
const ll infL = (ll)1e18;
const int N = 100005;
const ll mod = (ll)1e9 + 7;
const ll mod2 = 998244353LL;
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  vector<ll> store;
  store.push_back(1LL);
  for (ll base = 2; base <= 1e6; base++) {
    for (ll mul = base * base * base; mul <= 1e18; mul *= base) {
      store.push_back(mul);
      if (mul > (ll)1e18 / base) break;
    }
  }
  sort(store.begin(), store.end());
  store.erase(unique(store.begin(), store.end()), store.end());
  vector<ll> ans;
  for (ll& u : store) {
    ll root = sqrtl(u);
    if (root * root == u) continue;
    ans.push_back(u);
  }
  int q;
  cin >> q;
  while (q--) {
    ll l, r;
    cin >> l >> r;
    ll res = upper_bound(ans.begin(), ans.end(), r) -
             lower_bound(ans.begin(), ans.end(), l);
    res += (ll)sqrtl(r) - (ll)sqrtl(l - 1LL);
    cout << res << '\n';
  }
  return 0;
}
