#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const long long LIM = 1000000000000000000LL;
vector<long long> all;
long long solve(long long x) {
  if (x == 0) return 0;
  long long ret = 0;
  long long y = (long long)sqrt(1.0 * x);
  ret += y;
  int nall = upper_bound(all.begin(), all.end(), x) - all.begin();
  ret += nall;
  return ret;
}
void run() {
  for (int p = 3;; ++p) {
    bool any = false;
    for (long long a = 2;; ++a) {
      long long cur = a;
      for (int i = (0); i < (p - 1); ++i)
        cur = cur > LIM / a ? LLONG_MAX : cur * a;
      if (cur > LIM)
        break;
      else
        any = true;
      long long b = (long long)sqrt(1.0 * cur);
      if (b * b == cur) continue;
      all.push_back(cur);
    }
    if (!any) break;
  }
  sort(all.begin(), all.end());
  all.erase(unique(all.begin(), all.end()), all.end());
  int nq;
  scanf("%d", &nq);
  for (int qi = (0); qi < (nq); ++qi) {
    long long l, r;
    scanf("%lld%lld", &l, &r);
    long long ans = solve(r) - solve(l - 1);
    printf("%lld\n", ans);
  }
}
int main() {
  run();
  return 0;
}
