#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-9;
const int N = 1e6 + 5;
const long long LN = 1e18 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
long long q, l, r;
vector<long long> p;
set<long long> s;
long long raiz(long long x) {
  long long l = 0, r = INF, m;
  while (l < r) {
    m = (l + r + 1) / 2;
    if (m * m > x)
      r = m - 1;
    else
      l = m;
  }
  return l;
}
long long fastexp(long long b, long long e) {
  long long ans = 1;
  while (e) {
    if (e & 1) {
      if (ans > LN / b) return -1;
      ans = ans * b;
    }
    if (e == 1) return ans;
    if (b > LN / b) return -1;
    b = b * b;
    e /= 2;
  }
  return ans;
}
int main() {
  for (int i = 2; i <= N; i++) {
    for (int j = 3;; j++) {
      long long x = fastexp(i, j);
      if (x == -1) break;
      long long y = raiz(x);
      if (y * y != x) s.insert(x);
    }
  }
  for (auto it : s) p.push_back(it);
  cin >> q;
  while (q--) {
    cin >> l >> r;
    long long resp = upper_bound(p.begin(), p.end(), r) -
                     upper_bound(p.begin(), p.end(), l - 1);
    resp += (raiz(r) - raiz(l - 1));
    cout << resp << endl;
  }
}
