#include <bits/stdc++.h>
using namespace std;
set<long long int> s;
vector<long long int> v;
long long int dfs(long long int n) {
  if (!n) return 0;
  return upper_bound(v.begin(), v.end(), n) - v.begin() +
         (long long int)sqrt(n);
}
int main() {
  long long int x, y, z;
  for (long long int i = 2; i <= 1000000; i++) {
    x = i * i;
    z = 0;
    while (x <= 1000000000000000000 / i) {
      x *= i;
      y = sqrt(x);
      if (y * y != x) s.insert(x);
    }
  }
  for (auto it = s.begin(); it != s.end(); it++) {
    v.push_back(*it);
  }
  sort(v.begin(), v.end());
  long long int n, l, r, ans, ls, rs;
  cin >> n;
  for (int i = 0; i < n; i++) {
    ans = 0;
    cin >> l >> r;
    cout << (dfs(r) - dfs(l - 1)) << endl;
  }
  return 0;
}
