#include <bits/stdc++.h>
using namespace std;
const long long Inf = 1000000000000000000ll;
vector<long long> num;
map<long long, int> maap;
long long poow(long long k, long long i) {
  long long ret = 1;
  for (int j = 0; j < i; j++) {
    ret *= k;
  }
  return ret;
}
long long sqret(long long q) {
  long long pos = 0, find = q;
  for (int i = 31; i >= 0; i--) {
    if ((pos + (1LL << i)) * (pos + (1LL << i)) <= find) pos += (1LL << i);
  }
  return pos;
}
void pre() {
  for (int i = 3; i <= 61; i += 2) {
    for (int k = 2; poow(k, i) <= Inf; k++) {
      int tmp = sqrt(k);
      if (tmp * tmp == k) continue;
      if (maap[poow(k, i)] == 1) continue;
      num.push_back(poow(k, i));
      maap[poow(k, i)] = 1;
    }
  }
  sort(num.begin(), num.end());
}
long long find(long long f) {
  long long pos = 0;
  for (int i = 60; i >= 0; i--) {
    if ((pos + (1LL << i)) <= num.size() - 1)
      if (num[pos + (1LL << i)] <= f) pos += (1LL << i);
  }
  return pos + 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long m, l, r, res, tmp, tmp1;
  cin >> m;
  pre();
  while (m--) {
    cin >> l >> r;
    tmp = sqret(l - 1);
    tmp1 = sqret(r);
    res = find(r) - find(l - 1) + tmp1 - tmp;
    cout << res << endl;
  }
  return 0;
}
