#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 50;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
vector<long long> vec;
map<long long, int> mp;
bool square(long long x) {
  long long t = sqrt(x);
  if (t * t == x || (t + 1) * (t + 1) == x || (t - 1) * (t - 1) == x)
    return true;
  return false;
}
void prepare() {
  vec.push_back(1);
  for (long long i = 2; i <= 1e6; ++i) {
    for (long long t = i * i * i; t <= 1e18; t *= i) {
      if (!mp[t] && !square(t)) mp[t] = 1, vec.push_back(t);
      if (1ll * 1e18 / i < t) break;
    }
  }
  sort(vec.begin(), vec.end());
}
long long f(long long x) {
  long long l = 1, r = 1e9;
  long long ans = 0;
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (mid * mid <= x)
      ans = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  return ans;
}
int main(void) {
  prepare();
  long long q, l, r;
  cin >> q;
  while (q--) {
    scanf("%I64d%I64d", &l, &r);
    long long ans = 0;
    ans += f(r) - f(l - 1);
    ans += upper_bound(vec.begin(), vec.end(), r) -
           upper_bound(vec.begin(), vec.end(), l - 1);
    if (l == 1) ans--;
    printf("%I64d\n", ans);
  }
  return 0;
}
