import sys
import math
import heapq
import bisect
from collections import Counter
from collections import defaultdict
from io import BytesIO, IOBase
import string


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        import os
        self.os = os
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
        self.BUFSIZE = 8192

    def read(self):
        while True:
            b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            self.os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")


def get_int():
    return int(input())


def get_ints():
    return list(map(int, input().split(' ')))


def get_int_grid(n):
    return [get_ints() for _ in range(n)]


def get_str():
    return input().strip()


def get_strs():
    return get_str().split(' ')


def flat_list(arr):
    return [item for subarr in arr for item in subarr]


def yes_no(b):
    if b:
        return "YES"
    else:
        return "NO"


def binary_search(good, left, right, delta=1, right_true=False):
    """
    Performs binary search
    ----------
    Parameters
    ----------
    :param good: Function used to perform the binary search
    :param left: Starting value of left limit
    :param right: Starting value of the right limit
    :param delta: Margin of error, defaults value of 1 for integer binary search
    :param right_true: Boolean, for whether the right limit is the true invariant
    :return: Returns the most extremal value interval [left, right] which is good function evaluates to True,
            alternatively returns False if no such value found
    """

    limits = [left, right]
    while limits[1] - limits[0] > delta:
        if delta == 1:
            mid = sum(limits) // 2
        else:
            mid = sum(limits) / 2
        if good(mid):
            limits[int(right_true)] = mid
        else:
            limits[int(~right_true)] = mid
    if good(limits[int(right_true)]):
        return limits[int(right_true)]
    else:
        return False


def prefix_sums(a):
    p = [0]
    for x in a:
        p.append(p[-1] + x)
    return p


def solve_a():
    n = get_int()
    x = get_ints()
    x_enum = [(v, i) for i, v in enumerate(x)]
    x_enum.sort()
    if x_enum[0][0] != x_enum[1][0]:
        return x_enum[0][1] + 1
    else:
        return x_enum[-1][1] + 1


def solve_b():
    n = get_int()
    grid = [list(get_str()) for row in range(n)]
    points = []
    for i in range(n):
        for j in range(n):
            if grid[i][j] == '*':
                points.append((i, j))

    a, b = points

    if a[0] != b[0] and a[1] != b[1]:
        grid[a[0]][b[1]] = '*'
        grid[b[0]][a[1]] = '*'

    elif a[0] == b[0]:
        new = (a[0] + 1) % n
        grid[new][a[1]] = '*'
        grid[new][b[1]] = '*'

    elif a[1] == b[1]:
        new = (a[1] + 1) % n
        grid[a[0]][new] = '*'
        grid[b[0]][new] = '*'

    for row in grid:
        print(''.join(row))

    return


def solve_c():
    a, b = get_ints()
    s = list(get_str())
    a -= s.count('0')
    b -= s.count('1')
    n = len(s)

    for i in range(n):
        if s[i] == '1' and s[n - i - 1] == '?':
            s[n - i - 1] = '1'
            b -= 1
        if s[i] == '0' and s[n - i - 1] == '?':
            s[n - i - 1] = '0'
            a -= 1
    for i in range(n):
        if i != n - i - 1 and s[i] == s[n - i - 1] == '?':
            if a > 1:
                s[n - i - 1] = '0'
                s[i] = '0'
                a -= 2
            elif b > 1:
                s[n - i - 1] = '1'
                s[i] = '1'
                b -= 2
            else:
                return -1

    if s[n // 2] == '?':
        if a > 0:
            s[n // 2] = '0'
            a -= 1
        elif b > 0:
            s[n // 2] = '1'
            b -= 1
        else:
            return -1
    for i in range(n):
        if s[i] != s[n - i - 1]:
            return -1
    if (a != 0) or (b != 0):
        return -1
    else:
        return ''.join(s)


def solve_d():
    n = get_int()
    b = get_ints()

    b_set = {}

    b.sort()
    S = sum(b)

    # Random number is biggest
    if S - b[-1] - b[-2] == b[-2]:
        return b[:-2]

    # Random number is second biggest
    if S - b[-1] - b[-2] == b[-1]:
        return b[:-2]

    else:
        for i in range(n):
            # Random number is ith smallest i={1,...,n}
            if S - b[i] - b[-1] == b[-1]:
                return b[:i] + b[i+1:n+1]
    return [-1]


def solve_e():
    n, l, r, s = get_ints()


def linear_sieve(n):
    '''
    Calculates all the primes in {1,...,n} and the least prime factor for all integers {1,...,n}.
    Time complexity: O(n)
    Memory complexity: O(n)
    :param n: highest integer to consider
    :return: tuple:
    first element = array of primes;
    second element = array of least prime factors.
    '''
    # Initiate arrays for primes and least prime divisors
    primes = []
    least_prime_divs = [0] * (n + 1)
    # Iterate over all numbers in thr range, starting at 2
    for i in range(2, n + 1):
        # Any number which has not already been assigned a least prime divisor is a prime
        if not least_prime_divs[i]:
            least_prime_divs[i] = i
            primes.append(i)
        # Iterate over current (ordered) prime array
        for p in primes:
            # End iteration if we out of the range or the prime exceeds the LPD of current number
            if i * p > n or p > least_prime_divs[i]:
                break
            # Each number can only be assigned once, giving linear time complexity
            least_prime_divs[i * p] = p
    # Return prime array and array of least prime divisors
    return primes, least_prime_divs


def preprocess_g(n_max):
    cnt = [0] * (n_max + 1)
    ans = [-1] * (n_max + 1)

    for i in range(1, n_max + 1):
        j = i
        while j < n_max + 1:
            cnt[j] += i
            j += i
        if cnt[i] < n_max and ans[cnt[i]] == -1:
            ans[cnt[i]] = i
    return ans


def solve_g():
    n = get_int()
    return d[n]


t = get_int()
d = preprocess_g(10 ** 7)
ans = []
for _ in range(t):
    ans.append(solve_g())
print(*ans)
