#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18 + 10;
const int N = 1e6 + 10;
const long long mod = 1e9 + 7;
const int base = 131;
const double pi = acos(-1);
map<string, int> ml;
map<long long, long long> mp;
map<int, int> vi;
long long b[N], visrow[N], viscol[N], dep[N], num[N], a[N], n, m, k, x, y;
long long ex, ey, cnt, ans, sum, flag;
long long nex[N];
vector<long long> v;
map<long long, long long> dp[N];
set<long long> second;
string s, ss;
long long solve(long long x) {
  long long l = 0, r = 1e9, mid, ans;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (mid * mid <= x) {
      ans = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  for (long long i = 2; i <= 1e6; i++) {
    long long t = i * i * i;
    while (t <= inf) {
      if (solve(t) * solve(t) < t && !mp[t]) {
        v.push_back(t);
        mp[t] = 1;
      }
      if (t >= inf / i) break;
      t *= i;
    }
  }
  sort(v.begin(), v.end());
  int q;
  cin >> q;
  long long l, r;
  while (q--) {
    cin >> l >> r;
    ans = 0;
    ans +=
        upper_bound(v.begin(), v.end(), r) - lower_bound(v.begin(), v.end(), l);
    ans += solve(r) - solve(l - 1);
    cout << ans << endl;
  }
}
