#include <bits/stdc++.h>
using namespace std;
vector<long long> huh = {-5, -5, 1,  1,  0, 1,  -1, 1,  0,  0,  -1, 1, 0,
                         1,  -1, -1, 0,  1, 0,  1,  0,  -1, -1, 1,  0, 0,
                         -1, 0,  0,  1,  1, 1,  0,  -1, -1, -1, 0,  1, -1,
                         -1, 0,  1,  1,  1, 0,  0,  -1, 1,  0,  0,  0, -1,
                         0,  1,  0,  -1, 0, -1, -1, 1,  0,  1,  -1, 0, 0};
long long poww(long long x, long long y) {
  if (y == 0) return 1;
  if (y % 2)
    return x * poww(x, y - 1);
  else
    return poww(x * x, y / 2);
}
long long get_ans(long long k) {
  long long ans = 1;
  if (k == 0) return 0;
  int c = 2;
  int p = 1;
  while (p <= k) {
    p *= 2;
    c++;
  }
  for (int i = 2; i <= 60; i++) {
    long long r = pow((long double)k, (long double)1 / (long double)i) + 1e-8,
              m;
    if (poww(r, i) > k) {
      ans += huh[i] * (r - 2);
    } else
      ans += huh[i] * (r - 1);
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  int q;
  cout << endl;
  cin >> q;
  long long a, b;
  for (int i = 0; i < q; i++) {
    cin >> a >> b;
    cout << get_ans(b) - get_ans(a - 1) << '\n';
  }
  return 0;
}
