#include <bits/stdc++.h>
using namespace std;
const int MAXP = 59;
int a[MAXP + 1];
int mu[MAXP + 1];
int lpf[MAXP + 1];
int tc, ans;
long long l, r;
void fast_io() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
bool check(int x, int val, long long o) {
  for (int i = 1; i <= x; i++) {
    o /= val;
    if (!o) return 0;
  }
  return 1;
}
long long modpow(long long x, int y) {
  long long res = 1;
  while (y) {
    if (y & 1) res = (res * x);
    x = (x * x);
    y >>= 1;
  }
  return res;
}
int query(int i, long long val, bool p) {
  int lo = 1, hi = (p ? a[i] : 1e9);
  int res = 0;
  while (lo <= hi) {
    int mid = (lo + hi) >> 1;
    if (!p ? check(i, mid, val) : modpow(mid, i) <= val)
      res = mid, lo = mid + 1;
    else
      hi = mid - 1;
  }
  return res;
}
void sieve() {
  for (int i = 2; i <= MAXP; i++) {
    a[i] = query(i, 1e18, 0);
  }
  for (int i = 2; i <= MAXP; i++) {
    if (!lpf[i]) {
      lpf[i] = i;
      for (int j = (i << 1); j <= MAXP; j += i)
        if (!lpf[j]) lpf[j] = i;
    }
  }
  mu[1] = 1;
  for (int i = 2; i <= MAXP; i++) {
    if (lpf[i / lpf[i]] ^ lpf[i]) mu[i] = -1 * mu[i / lpf[i]];
  }
}
int main() {
  fast_io();
  sieve();
  cin >> tc;
  while (tc--) {
    cin >> l >> r;
    ans = 0;
    for (int i = 2; i <= MAXP; i++) {
      if (!mu[i]) continue;
      bool o = (i != 2) & !(l ^ 1);
      ans -= mu[i] * (query(i, r, 1) - query(i, l - 1, 1) - o);
    }
    cout << ans << '\n';
  }
  return 0;
}
