#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  return x * f;
}
int T, prime[110], mobius[110], cnt = 0;
bool flag[110];
long long calc(long long n, int k) {
  long double p = pow(n, (long double)1 / k);
  long long a = p;
  if ((long long)(p + 1E-6) > a) {
    long long s = 1;
    for (int i = 1; i <= k; i++) {
      s = s * (a + 1);
      if (s > n) break;
    }
    if (s <= n) return a + 1;
  }
  return a;
}
int main() {
  flag[1] = 1;
  mobius[1] = 1;
  for (int i = 2; i <= 100; i++) {
    if (!flag[i]) prime[++cnt] = i, mobius[i] = -1;
    for (int j = 1; prime[j] * i <= 100 && j <= cnt; j++) {
      flag[prime[j] * i] = 1;
      if (i % prime[j] == 0) break;
      mobius[prime[j] * i] = -mobius[i];
    }
  }
  T = read();
  while (T--) {
    long long m = read(), n = read(), ans = 0;
    for (int i = 1; i <= 60; i++)
      if (mobius[i]) ans += mobius[i] * (calc(n, i) - calc(m - 1, i));
    printf("%I64d\n", n - m - ans + (m > 1));
  }
  return 0;
}
