#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:36777216")
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-11;
const int oo = 0x3f3f3f3f;
template <class T>
inline void checkmin(T &a, T b) {
  if (b < a) a = b;
}
template <class T>
inline void checkmax(T &a, T b) {
  if (b > a) a = b;
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
template <class T>
inline T lowbit(T n) {
  return (n ^ (n - 1)) & n;
}
template <class T>
inline int countbit(T n) {
  return (n == 0) ? 0 : (1 + countbit(n & (n - 1)));
}
template <class T>
inline T gcd(T a, T b) {
  T c;
  while (a != 0) {
    c = a;
    a = b % a;
    b = c;
  }
  return b;
}
template <class T>
inline T mabs(T a) {
  if (a < 0)
    return -a;
  else
    return a;
}
typedef vector<int> VI;
typedef vector<VI> VII;
typedef vector<string> VS;
const int N = (int)1e7 + 111;
const int MOD = (int)1e9 + 7;
const long long MQ = (long long)1e18;
long long allas[N];
int mark[N], ap;
inline void prep() {
  ap = 0;
  memset(mark, 0, sizeof(mark));
  for (long long p = 2; p < N; ++p) {
    if (mark[(int)p]) continue;
    long long ps = p * p;
    long long a = p;
    while (MQ / ps >= a) {
      a *= ps;
      if (a < N) {
        assert(!mark[(int)a]);
        mark[(int)a] = 1;
      }
      allas[ap++] = a;
    }
    a = 1LL;
    while (N / ps >= a) {
      a *= ps;
      if (a < N) {
        assert(!mark[(int)a]);
        mark[(int)a] = 1;
      }
    }
  }
  assert(ap <= N);
  sort(allas, allas + ap);
}
inline long long doit(long long lim) {
  int rp = (upper_bound(allas, allas + ap, lim) - allas);
  double droot = sqrtl(1.0 * lim);
  long long root = (long long)droot;
  if (root * root > lim) root = max(1LL, root - 1);
  return (long long)(1LL * rp + root);
}
inline int solve(int testnum) {
  long long l, r;
  scanf("%lld%lld", &l, &r);
  long long res = doit(r) - doit(l - 1);
  printf("%lld\n", res);
  return 0;
}
int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
  prep();
  int t = 1;
  scanf("%d", &t);
  if (argc > 1) t = atoi(argv[1]);
  for (int _t = (1); _t < int(t + 1); _t++) {
    int ret = ::solve(_t);
    if (ret == -1) {
      cerr << "Failed test #" << _t << endl;
      break;
    }
    cerr << "Solved test #" << _t << endl;
  }
  return 0;
}
