#include <bits/stdc++.h>
using namespace std;
long long l, r;
const long long maxn = 2e6 + 200;
const long long h = 1e18;
int cnt;
long long k[maxn];
int getsqrt(long long a) {
  int s = ceil(sqrt(a));
  for (long long i = s - 2; i < s + 2; i++) {
    if (i * i == a) {
      return i;
    }
  }
  return -1;
}
void init() {
  long long i, j;
  cnt = 0;
  unordered_map<long long, long long> p;
  p.clear();
  for (i = 2; i <= 1e6; i++) {
    for (j = i * i; j <= h / i;) {
      j = j * i;
      long double a = j;
      long long key = sqrt(a);
      if (key * key == j) continue;
      if (p[j]) continue;
      p[j] = 1;
      k[++cnt] = j;
    }
  }
}
long long fun(long long x) {
  return upper_bound(k + 1, k + 1 + cnt, x) - k + (long long)sqrt(x);
}
int main() {
  int i, j;
  int q;
  init();
  sort(k + 1, k + 1 + cnt);
  cin >> q;
  while (q--) {
    long long a, b;
    cin >> a >> b;
    l = a;
    r = b;
    l--;
    long long ans = 0;
    ans = fun(r) - fun(l);
    cout << ans << endl;
  }
  return 0;
}
