#include <bits/stdc++.h>
using namespace std;
namespace FGF {
int n;
const int N = 2e6 + 5;
long long a[N], cnt, m = 1e18;
void init() {
  for (long long i = 2; i * i * i <= m; i++) {
    long long s = i * i;
    while (s <= m / i) {
      s *= i;
      long long tmp = sqrt(s);
      if (tmp * tmp != s) a[++cnt] = s;
    }
  }
  sort(a + 1, a + cnt + 1);
  cnt = unique(a + 1, a + cnt + 1) - a - 1;
}
void work() {
  init();
  scanf("%d", &n);
  while (n--) {
    long long l, r;
    scanf("%lld%lld", &l, &r);
    long long ans = upper_bound(a + 1, a + cnt + 1, r) -
                    lower_bound(a + 1, a + cnt + 1, l) + (long long)sqrt(r) -
                    (long long)sqrt(l - 1);
    printf("%lld\n", ans);
  }
}
}  // namespace FGF
int main() {
  FGF::work();
  return 0;
}
