#include <bits/stdc++.h>
using namespace std;
long long L = 0, R = 0;
double minA = 0, maxA = 0;
long long floor_minA = 0, floor_maxA = 0;
long long pow(long long base, int power) {
  if (power == 2)
    return base * base;
  else if (power == 3)
    return base * base * base;
  else if (power % 2)
    return pow(base * base, power / 2) * base;
  else
    return pow(base * base, power / 2);
}
int inaccuracy(int power) {
  int correct = 0;
  if (minA - floor_minA < 0.1 && pow(floor_minA, power) >= L)
    correct++;
  else if (minA - floor_minA > 0.9 && pow(floor_minA + 1, power) < L)
    correct--;
  if (maxA - floor_maxA < 0.1 && pow(floor_maxA, power) > R)
    correct--;
  else if (maxA - floor_maxA > 0.9 && pow(floor_maxA + 1, power) <= R)
    correct++;
  return correct;
}
int main() {
  int primes[17] = {2,  3,  5,  7,  11, 13, 17, 19, 23,
                    29, 31, 37, 41, 43, 47, 53, 59};
  int result = 0;
  int size = 0;
  int p = 0, p1 = 0, p2 = 0;
  int pq = 0;
  cin >> size;
  for (int cnt = 0; cnt < size; cnt++) {
    result = 0;
    cin >> L >> R;
    if (L == 1) {
      result++;
      L = 2;
    }
    for (p = 0; p < 17; p++) {
      if ((maxA = pow(R, 1.0 / primes[p])) < 2)
        break;
      else {
        minA = pow(L, 1.0 / primes[p]);
        floor_minA = floor(minA);
        floor_maxA = floor(maxA);
        result += floor_maxA - floor_minA + inaccuracy(primes[p]);
      }
    }
    for (p1 = 0; p1 < 3; p1++) {
      for (p2 = p1 + 1; p2 < 10; p2++) {
        if ((pq = primes[p1] * primes[p2]) > 59)
          break;
        else {
          if ((maxA = pow(R, 1.0 / pq)) < 2)
            break;
          else {
            minA = pow(L, 1.0 / pq);
            floor_minA = floor(minA);
            floor_maxA = floor(maxA);
            result -= floor_maxA - floor_minA + inaccuracy(pq);
          }
        }
      }
    }
    if ((maxA = pow(R, 1.0 / 30)) >= 2) {
      minA = pow(L, 1.0 / 30);
      floor_minA = floor(minA);
      floor_maxA = floor(maxA);
      result += floor_maxA - floor_minA + inaccuracy(30);
    }
    if ((maxA = pow(R, 1.0 / 42)) >= 2) {
      minA = pow(L, 1.0 / 42);
      floor_minA = floor(minA);
      floor_maxA = floor(maxA);
      result += floor_maxA - floor_minA + inaccuracy(42);
    }
    cout << result << endl;
  }
}
