#include <bits/stdc++.h>
using namespace std;
vector<long long> cnt;
long long solve(long long r) {
  return (upper_bound(cnt.begin(), cnt.end(), r) - cnt.begin()) +
         (long long)sqrt(r);
}
signed main() {
  vector<long long> kek = {1, 5, 7, 10, 15};
  vector<long long> cnt__;
  for (long long a = 2; a <= 1e6; a++) {
    long long cur = a * a * a;
    while (1) {
      cnt__.push_back(cur);
      if (cur > (long long)1e18 / a) break;
      cur *= a;
    }
  }
  sort(cnt__.begin(), cnt__.end());
  cnt__.erase(unique(cnt__.begin(), cnt__.end()), cnt__.end());
  for (long long v : cnt__) {
    long long x = sqrt(v);
    if (x * x != v) cnt.push_back(v);
  }
  sort(cnt.begin(), cnt.end());
  cnt.erase(unique(cnt.begin(), cnt.end()), cnt.end());
  long long q;
  cin >> q;
  while (q--) {
    long long l, r;
    cin >> l >> r;
    cout << solve(r) - solve(l - 1) << endl;
  }
}
