#include <bits/stdc++.h>
using namespace std;
vector<unsigned long long> v;
unsigned long long solve(unsigned long long x) {
  unsigned long long l = 1, r = (unsigned long long)(1e9), ans = 0;
  while (l <= r) {
    unsigned long long m = (l + r) / 2;
    if ((m * m) > x) {
      r = m - 1;
    } else {
      ans = m;
      l = m + 1;
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  set<unsigned long long> s;
  for (unsigned long long i = 2; i <= 1000000; i++) {
    unsigned long long x = i * i * i;
    while (1) {
      unsigned long long y = sqrtl(x);
      if (y * y != x) {
        s.insert(x);
      }
      if ((unsigned long long)(1e18) / i >= x) {
        x *= i;
      } else {
        break;
      }
    }
  }
  for (auto it = s.begin(); it != s.end(); it++) {
    v.push_back(*it);
  }
  for (int i = 0; i < n; i++) {
    unsigned long long l, r;
    cin >> l >> r;
    unsigned long long ans = (upper_bound(v.begin(), v.end(), r) - v.begin()) -
                             (lower_bound(v.begin(), v.end(), l) - v.begin());
    ans = ans + solve(r) - solve(l - 1);
    cout << ans << endl;
  }
}
