#include <bits/stdc++.h>
using namespace std;
const int N = 100;
int yep[N];
int prime[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59};
vector<long long> c;
bool check(long long n) {
  long long tmp = sqrt(n);
  while (tmp * tmp < n) tmp++;
  while (tmp * tmp > n) tmp--;
  return (tmp * tmp) == n;
}
void init() {
  for (int i = 0; i < 60; ++i) yep[i] = 1;
  for (int i = 0; i < 60; ++i)
    for (int j = 0; j < 17; ++j)
      if (i % prime[j] == 0) yep[i] = -yep[i];
  for (int i = 0; i < 60; ++i)
    for (int j = 0; j < 17; ++j)
      if (i % (prime[j] * prime[j]) == 0) yep[i] = 0;
  for (int i = 3; i < 60; ++i) {
    for (int l = 2;; ++l) {
      if (i * log10(l) > 18) {
        break;
      }
      long long nani = 1;
      for (int o = 0; o < i; ++o) nani *= l;
      if (!check(nani)) c.push_back(nani);
    }
  }
  sort(c.begin(), c.end());
  c.resize(distance(c.begin(), unique(c.begin(), c.end())));
}
int n;
int main() {
  init();
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    long long q;
    cin >> q;
    long long tmp = sqrt(q);
    while (tmp * tmp > q) tmp--;
    while ((tmp + 1) * (tmp + 1) <= q) tmp++;
    cout << q - tmp - (lower_bound(c.begin(), c.end(), q + 1) - c.begin())
         << "\n";
  }
}
