#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  set<long long> ans;
  set<long long>::iterator it;
  vector<long long> arr;
  long long n = 1e6;
  for (long long i = 2; i <= n; i++) {
    long long sum = i * i;
    while (sum <= (long long)1e18) {
      long long x = ceil(sqrt(sum));
      if ((x * x) != sum) {
        ans.insert(sum);
      }
      if (sum > ((long long)(1e18 / i))) break;
      sum = sum * i;
    }
  }
  for (it = ans.begin(); it != ans.end(); it++) {
    arr.push_back(*it);
  }
  cin >> t;
  vector<long long>::iterator hi, lo;
  for (int j = 1; j <= t; j++) {
    long long l, r;
    cin >> l >> r;
    long long now;
    hi = upper_bound(arr.begin(), arr.end(), r);
    lo = upper_bound(arr.begin(), arr.end(), l - 1);
    long long res = (hi - lo);
    res += (long long)(sqrt(r)) - (long long)(sqrt(l - 1));
    cout << res << "\n";
  }
  return 0;
}
