#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005, mod = 1e9 + 7;
const long long inf = 1e18;
int a[maxn], b[maxn];
map<int, int> mp;
set<long long> st;
vector<long long> vv, v;
long long solve(long long x) {
  long long l = 1, r = 1e9, 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;
}
void init() {
  for (long long i = 2; i <= 1e6; i++) {
    for (long long j = i * i * i; j <= inf; j *= i * i) {
      v.push_back(j);
      if (j > (inf / (i * i))) break;
    }
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  for (int i = 0; i < v.size(); i++) {
    if (solve(v[i]) * solve(v[i]) == v[i]) continue;
    vv.push_back(v[i]);
  }
}
int main() {
  ios::sync_with_stdio(false);
  init();
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    long long l, r, ans;
    cin >> l >> r;
    int pos1 = upper_bound(vv.begin(), vv.end(), l - 1) - vv.begin();
    int pos2 = upper_bound(vv.begin(), vv.end(), r) - vv.begin();
    long long cnt = pos2 - pos1;
    ans = solve(r) - solve(l - 1) + cnt;
    cout << ans << '\n';
  }
  return 0;
}
