import sys from operator import itemgetter from collections import defaultdict import bisect stdin=sys.stdin sys.setrecursionlimit(10 ** 8) ip=lambda: int(sp()) fp=lambda: float(sp()) lp=lambda:list(map(int,stdin.readline().split())) sp=lambda:stdin.readline().rstrip() Yp=lambda:print('Yes') Np=lambda:print('No') inf = 1 << 60 eps = 1e-9 sortkey = itemgetter(0) def hantei(x): y = int(x ** (1/2)) return y * y == x def f(x): ok = 1 ng = 10 ** 9 + 1 while abs(ok - ng) > 1: mid = (ok + ng) // 2 if mid * mid > x: ng = mid else: ok = mid return ok T = ip() Max = 10 ** 18 rui = [] ## **3~を考える ## 2 ** 60 > 10 ** 18なので考える累乗はたかだか59かつ奇数 for i in range(3, 60): if i & 1: for j in range(1,10 ** 6 + 1): if j ** i > Max: break if hantei(j): continue rui.append(j ** i) rui.sort() L = len(rui) ind = [0 for _ in range(L)] de = defaultdict(int) for i in range(L): tar = f(rui[i]) ind[i] = tar + i + 1 de[tar + i + 1] = rui[i] for _ in range(T): K = ip() if de[K] != 0: ans = de[K] else: now = bisect.bisect_left(ind, K) ans = (K - now) ** 2 print(ans)