#include <bits/stdc++.h>
using namespace std;
vector<long long> V;
set<long long> S;
set<long long>::iterator it;
vector<long long>::iterator it1, it2;
void Preprocess() {
  long long val, x, i;
  for (i = 2; i <= 1e6; ++i) {
    for (x = i * i * i; x <= 1e18; x *= i) {
      val = sqrt(x);
      if (val * val != x) S.insert(x);
      if (x > 1e18 / i) break;
    }
  }
  for (it = S.begin(); it != S.end(); ++it) V.emplace_back(*it);
  S.clear();
}
int main() {
  int q;
  long long l, r, Ans, low, high;
  Preprocess();
  scanf("%d", &q);
  while (q--) {
    scanf("%lld%lld", &l, &r);
    it1 = lower_bound(V.begin(), V.end(), l);
    it2 = upper_bound(V.begin(), V.end(), r);
    if (int(it2 - it1) >= 0)
      Ans = int(it2 - it1);
    else
      Ans = 0;
    low = sqrt(l);
    high = sqrt(r);
    if (low * low < l)
      ++low;
    else if ((low - 1) * (low - 1) >= l)
      --low;
    if (high * high > r)
      --high;
    else if ((high + 1) * (high + 1) <= r)
      ++high;
    if (high >= low) Ans += high - low + 1;
    printf("%lld\n", Ans);
  }
  return 0;
}
