#include <bits/stdc++.h>
using namespace std;
long long logab(long long a, long long b) {
  long long ans = 0;
  while (b > 0) {
    ans++;
    b /= a;
  }
  return ans;
}
long long pwr(long long a, long long b) {
  if (a < 0) return -1;
  long long ans = 1;
  while (b--) ans *= a;
  return ans;
}
int b = 7;
string toBString(int x) {
  string s = "";
  for (int i = 0; i < b; i++) {
    if (x & 1)
      s += '1';
    else
      s += '0';
    x /= 2;
  }
  reverse(s.begin(), s.end());
  return s;
}
long long diff(long long a, long long b) {
  int s = 0, e = 1e9;
  int m1, m2;
  while (s <= e) {
    m1 = (s + e) / 2;
    long long x = pwr(m1, 2);
    long long y = pwr(m1 - 1, 2);
    if (x >= a && y < a) {
      break;
    }
    if (x < a) {
      s = m1 + 1;
    } else {
      e = m1 - 1;
    }
  }
  s = 0;
  e = 1e9;
  while (s <= e) {
    m2 = (s + e) / 2;
    long long x = pwr(m2, 2);
    long long y = pwr(m2 + 1, 2);
    if (x <= b && y > b) {
      cout << x << " " << y << endl;
      break;
    }
    if (x < b) {
      s = m2 + 1;
    } else {
      e = m2 - 1;
    }
  }
  return (m2 + 1) - m1;
}
vector<long long> lol;
map<long long, bool> nop;
int main() {
  for (long long j = 2; j <= 1e6; j++) {
    long long x = j;
    while (1e18 / j > x) {
      x *= j;
      long long z = sqrt(x);
      if (z * z != x && !nop[x]) lol.push_back(x);
      nop[x] = 1;
    }
  }
  sort(lol.begin(), lol.end());
  int q;
  cin >> q;
  while (q--) {
    long long x, y;
    cin >> x >> y;
    long long lb = upper_bound(lol.begin(), lol.end(), x - 1) - lol.begin();
    long long ub = upper_bound(lol.begin(), lol.end(), y) - lol.begin();
    long long total = ub - lb;
    if (x == 1) total = ub;
    total += (int)sqrt(y);
    if (x != 1) total -= (int)sqrt(x - 1);
    cout << total << endl;
  }
}
