#include <bits/stdc++.h>
using namespace std;
const long long int lim = 1e18;
set<long long int> powers;
vector<long long int> v;
bool ok(long long int cur, int i) {
  if (cur <= (lim / (1LL * i)))
    return true;
  else
    return false;
}
int sqrt(long long int x) {
  int lo = 1, high = (int)1e9;
  while (lo <= high) {
    int mid = (lo + high) / 2;
    if (1LL * mid * mid <= x)
      lo = mid + 1;
    else
      high = mid - 1;
  }
  return lo - 1;
}
bool square(long long int x) {
  long long int res = sqrt(x);
  return res * res == x;
}
void precomp() {
  powers.clear();
  for (int i = 2; i <= 1000000; i++) {
    long long int cur = 1LL * i * i * i;
    while (cur <= lim) {
      if (!square(cur)) {
        powers.insert(cur);
      }
      if (ok(cur, i)) {
        cur = cur * i * 1LL;
      } else
        break;
    }
  }
  for (set<long long int>::iterator it = powers.begin(); it != powers.end();
       it++) {
    v.push_back(*it);
  }
}
long long int lower_bound(long long int x) {
  long long int lo = 0, high = v.size() - 1;
  while (lo <= high) {
    int mid = (lo + high) / 2;
    if (v[mid] <= x)
      lo = mid + 1;
    else
      high = mid - 1;
  }
  return lo;
}
long long int solve(long long int x) {
  if (!x) return 0;
  return sqrt(x) + lower_bound(x);
}
int main() {
  ios::sync_with_stdio(false);
  precomp();
  int n;
  cin >> n;
  while (n--) {
    long long int l, r;
    cin >> l >> r;
    cout << solve(r) - solve(l - 1) << endl;
  }
  return 0;
}
