#include <bits/stdc++.h>
using namespace std;
vector<long long> num;
vector<long long> vals;
long long root(long long x) {
  long long l = 0, r = 1e9 + 1;
  while (l < r - 1) {
    long long m = (l + r) / 2;
    if (m * m > x)
      r = m;
    else
      l = m;
  }
  return l;
}
void init() {
  for (int i = 2; i <= 1e6; i++) {
    int val = root(i);
    if (val * val == i) continue;
    long long t = 1ll * i * i;
    if (t < 0) {
      cout << t << endl;
      break;
    }
    int cnt = 0;
    while (t <= 1e18 / i) {
      t *= i;
      cnt++;
      if (cnt & 1) num.push_back(t);
    }
  }
  sort(num.begin(), num.end());
  num.erase(unique(num.begin(), num.end()), num.end());
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  init();
  long long q;
  cin >> q;
  while (q--) {
    long long l, r;
    cin >> l >> r;
    cout << (long long)root(r) - (long long)root(l - 1) +
                (upper_bound(num.begin(), num.end(), r) -
                 lower_bound(num.begin(), num.end(), l))
         << endl;
  }
  return 0;
}
