def sqrt(n, k = 2): if n == 0: return 0 l = k - 1 if not n: return 0 y = 1 << (n.bit_length() + l) // k x = y + 1 while y < x: x = y y = (l * x + n // (x ** l)) // k return x def cnt(n): s = 1 for b in range(2, 31): s += W[b] * (sqrt(n, b) - 1) return s W = [0, 0, 1, 1, 0, 1, -1, 1, 0, 0, -1, 1, 0, 1, -1, -1, 0, 1, 0, 1, 0, -1, -1, 1, 0, 0, -1, 0, 0, 1, 1] T = int(input()) for _ in range(T): K = int(input()) l, r = 0, 10 ** 18 while r - l > 1: m = l + r >> 1 if cnt(m) < K: l = m else: r = m print(r)