#include <bits/stdc++.h>
using namespace std;
long long SQR(long long x) {
  long long mn = 1, mx = min((1LL << 30), x);
  long long ans = 1;
  while (mn <= mx) {
    long long md = (mn + mx) / 2;
    if (md * md > x)
      mx = md - 1;
    else
      ans = md, mn = md + 1;
  }
  return ans;
}
long long MAX = 1e18;
int main() {
  vector<long long> a;
  for (int i = 2; i <= 1000000; i++) {
    long long p = 1LL * i * i;
    while (p <= MAX / i) {
      p *= i;
      long long s = SQR(p);
      if (s * s != p) a.push_back(p);
    }
  }
  sort(a.begin(), a.end());
  a.resize(unique(a.begin(), a.end()) - a.begin());
  int T;
  scanf("%d", &T);
  while (T--) {
    long long n;
    scanf("%I64d", &n);
    long long ans = upper_bound(a.begin(), a.end(), n) - a.begin();
    ans += SQR(n);
    printf("%I64d\n", n - ans);
  }
}
