#include <bits/stdc++.h>
using namespace std;
vector<long long> v, v1;
const long long MAX = 1e18;
void pre() {
  for (long long i = 2; i < 1000000; i++) {
    long long p = i * i * i;
    long long sq = sqrt(i);
    if (sq * sq == i) continue;
    while (p > 0 and p < MAX and p % i == 0) {
      long long x = sqrt(p);
      if (x * x != p) v.push_back(p);
      p *= i;
    }
  }
  sort(v.begin(), v.end());
  v1.push_back(v[0]);
  for (long long i = 1; i < v.size(); i++)
    if (v[i] != v[i - 1]) v1.push_back(v[i]);
}
int main() {
  pre();
  long long l, r;
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%lld %lld", &l, &r);
    long long ans = upper_bound(v1.begin(), v1.end(), r) -
                    upper_bound(v1.begin(), v1.end(), l - 1LL);
    long long x = sqrt(l - 1LL + 1e-9);
    long long y = sqrt(r + 1e-9);
    ans += (y - x);
    printf("%lld\n", ans);
  }
}
