#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
inline bool uin(T& a, T b) {
  return a > b && (a = b, true);
}
template <class T>
inline bool uax(T& a, T b) {
  return a < b && (a = b, true);
}
class CSadPowers {
  ll root(ll x) {
    ll l = 0, r = 1e9 + 1;
    while (l < r) {
      ll m = (l + r + 1LL) / 2;
      if (m * m <= x)
        l = m;
      else
        r = m - 1;
    }
    return l;
  }

 public:
  void solve(std::istream& cin, std::ostream& cout) {
    vector<ll> nos;
    for (ll i = 2; i <= 1e6; ++i) {
      for (ll cur = i * i * i; cur <= 1e18L; cur *= i) {
        nos.push_back(cur);
        if (cur > (1e18L) / i) break;
      }
    }
    sort(nos.begin(), nos.end());
    nos.resize(unique(nos.begin(), nos.end()) - nos.begin());
    vector<ll> nos_nosq;
    for (ll i : nos) {
      ll sq = root(i);
      if (sq * sq == i) continue;
      nos_nosq.push_back(i);
    }
    int tt;
    cin >> tt;
    while (tt--) {
      ll low, hig;
      cin >> low >> hig;
      int ans = root(hig) - root(low - 1);
      ans += upper_bound(nos_nosq.begin(), nos_nosq.end(), hig) -
             lower_bound(nos_nosq.begin(), nos_nosq.end(), low);
      cout << ans << '\n';
    }
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  CSadPowers solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
