#include <bits/stdc++.h>
using namespace std;
unsigned long long n;
unsigned long long mp[65];
unsigned long long mul(unsigned long long a, unsigned long long b) {
  return a > n / b ? n + 1 : a * b;
}
unsigned long long power(unsigned long long a, int e) {
  if (!e) return 1;
  return e & 1 ? mul(power(a, e - 1), a) : power(mul(a, a), e >> 1);
}
unsigned long long f(int x) {
  if (mp[x] != -1) return mp[x];
  unsigned long long ans = pow(1.0 * n, 1.0 / x);
  if (ans < 0) ans = 0;
  while (power(ans + 1, x) <= n) ans++;
  ans--;
  for (int i = x + x; i <= 60; i += x) ans -= f(i);
  return mp[x] = ans;
}
unsigned long long calc(unsigned long long x) {
  if (x == 0) return 0;
  n = x;
  unsigned long long ans = 1;
  memset(mp, -1, sizeof(mp));
  for (int i = 60; i >= 2; i--) ans += f(i);
  return ans;
}
int main() {
  int T;
  unsigned long long l, r;
  scanf("%d", &T);
  while (T--) {
    scanf("%lld %lld", &l, &r);
    printf("%lld\n", calc(r) - calc(l - 1));
  }
  return 0;
}
