#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const long long INF = 1e18;
const int N = 2e5 + 7;
const int M = 5e6 + 7;
vector<long long> f;
long long cnt = 0;
long long Log(int p) {
  long long ans = (long long)floor(log(1.00 * INF) / log(1.00 * p));
  return ans;
}
long long Pow(long long x, int p) {
  cnt += (long long)p;
  long long ans = 1ll;
  while (p--) ans *= x;
  return ans;
}
long long sum(long long x) {
  long long idx = lower_bound(f.begin(), f.end(), x) - f.begin();
  if (idx < f.size() && f[idx] > x) idx--;
  if (idx == f.size()) idx--;
  return (long long)sqrt(x) + idx;
}
signed main() {
  ios::sync_with_stdio(false);
  for (int p = 3; p <= 60; p++)
    for (long long x = 2;
         x <= (long long)floor(pow(1.00 * INF, 1.00 / (p * 1.00))); x++) {
      long long y = Pow(x, p);
      long long z = (long long)sqrt(y * 1.00);
      if (z * z != y) f.push_back(y);
    }
  sort(f.begin(), f.end());
  f.erase(unique(f.begin(), f.end()), f.end());
  int q;
  cin >> q;
  while (q--) {
    long long l, r;
    cin >> l >> r;
    cout << sum(r) - sum(l - 1) << "\n";
  }
  return 0;
}
