#include <bits/stdc++.h>
const int MAX = 1e6 + 10;
const int MOD = 1e9 + 7;
using namespace std;
vector<long long> v, vv;
int vis[MAX];
int main() {
  ios::sync_with_stdio(false), cout.tie(NULL);
  v.push_back(1);
  vv.push_back(1);
  for (int i = 2; i <= 1000000; i++) {
    if (vis[i]) continue;
    vv.push_back(i);
    long long sum = i;
    while (sum <= 2000000000000000000ll / i) {
      sum *= i;
      if (sum <= 1000000) vis[sum] = 1;
      v.push_back(sum);
      vv.push_back(sum);
    }
  }
  sort(v.begin(), v.end());
  sort(vv.begin(), vv.end());
  int q;
  cin >> q;
  while (q--) {
    long long l, r;
    cin >> l >> r;
    long long x = sqrt(l), y = sqrt(r);
    if (x * x > l) {
      while ((x - 1) * (x - 1) >= l) x--;
    } else {
      while ((x + 1) * (x + 1) < l) x++;
      x++;
    }
    if (y * y > r) {
      while ((y - 1) * (y - 1) > r) y--;
      y--;
    } else {
      while ((y + 1) * (y + 1) <= r) y++;
    }
    long long lt = lower_bound(vv.begin(), vv.end(), x) - vv.begin(),
              rt = upper_bound(vv.begin(), vv.end(), y) - vv.begin();
    long long ans = (y - x + 1) - (rt - lt);
    lt = lower_bound(v.begin(), v.end(), l) - v.begin(),
    rt = upper_bound(v.begin(), v.end(), r) - v.begin();
    ans += rt - lt;
    cout << ans << '\n';
  }
  return 0;
}
