import sys from operator import itemgetter from collections import defaultdict, deque import heapq 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) Max = 10 ** 18 def hantei(x): y = int(x ** (1 / 2)) return y ** 2 == x def f(x): ok = 1 ng = 10 ** 9 + 1 while abs(ok - ng) > 1: mid = (ok + ng) // 2 if mid ** 2 > x: ng = mid else: ok = mid return ok ruijou_3 = set() for j in range(3,60): if j & 1: for i in range(2, 10 ** 6 + 1): if i ** j > Max: break if hantei(i ** j): continue else: ruijou_3.add(i ** j) ruijou_3 = list(ruijou_3) ruijou_3.sort() di = defaultdict(int) index = [] for i in range(len(ruijou_3)): now = ruijou_3[i] tar = f(now) + i + 1 index.append(tar) di[tar] = now T = ip() for _ in range(T): now = ip() if di[now] != 0: print(di[now]) else: tar = bisect.bisect_left(index, now) ans = (now - tar) ** 2 print(ans)