#include <bits/stdc++.h>
using namespace std;
using Long = long long;
void solve() {
  vector<Long> powers;
  powers.reserve(1003479);
  for (int x = 2; x <= (int)1e6; ++x) {
    int root2 = sqrt(x);
    if (root2 * root2 != x) {
      Long x2 = (Long)x * x;
      Long pow = x;
      while ((long double)pow * x2 <= 1e18l) {
        pow *= x2;
        powers.push_back(pow);
      }
    }
  }
  sort(begin(powers), end(powers));
  powers.erase(unique(begin(powers), end(powers)), end(powers));
  if (fesetround(FE_TOWARDZERO)) {
    throw runtime_error{"can't set rounding mode"};
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    Long from, to;
    cin >> from >> to;
    auto a = lower_bound(begin(powers), end(powers), from);
    auto b = upper_bound(begin(powers), end(powers), to);
    int ans = b - a + (int)sqrtl(to) - (int)sqrtl(from - 1);
    cout << ans << '\n';
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout.precision(10);
  cout << fixed;
  solve();
  return 0;
}
