

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.StringTokenizer;

public final class G {

    // 1348393
    // 10000000
    public static void main(String[] args) {
        final FastScanner fs = new FastScanner();
        final int t = fs.nextInt();
        final Map<Long, Integer> map = new HashMap<>();
        long prev = 0;
        for (int n = 1; n <= (int) 1e5; n++) {
            final long curr = f(n);
            final Integer key = map.get(curr - prev);
            if (key == null) {
                map.put(curr - prev, n);
            } else if (n < key) {
                map.put(curr - prev, n);
            }
            prev = curr;
        }
        final StringBuilder sb = new StringBuilder();
        for (int test = 0; test < t; test++) {
            final long n = fs.nextLong();
            sb.append(map.getOrDefault(n, -1));
            sb.append('\n');
        }
        System.out.println(sb);
    }

    private static long sum(int n) {
        return ((long) n * (n + 1)) / 2;
    }

    private static long f(int n) {
        long res = 0;
        int i = 1;
        int loop = 0;
        while (true) {
            res += (sum(n / i) - sum(n / (i + 1))) * i;
            if (i == n) {
                break;
            }
            i = n / (n / (i + 1));
            loop++;
        }
        return res;
    }

    static final class Utils {
        private static class Shuffler {
            private static void shuffle(int[] x) {
                final Random r = new Random();

                for (int i = 0; i <= x.length - 2; i++) {
                    final int j = i + r.nextInt(x.length - i);
                    swap(x, i, j);
                }
            }

            private static void shuffle(long[] x) {
                final Random r = new Random();

                for (int i = 0; i <= x.length - 2; i++) {
                    final int j = i + r.nextInt(x.length - i);
                    swap(x, i, j);
                }
            }

            private static void swap(int[] x, int i, int j) {
                final int t = x[i];
                x[i] = x[j];
                x[j] = t;
            }

            private static void swap(long[] x, int i, int j) {
                final long t = x[i];
                x[i] = x[j];
                x[j] = t;
            }
        }

        public static void shuffleSort(int[] arr) {
            Shuffler.shuffle(arr);
            Arrays.sort(arr);
        }

        public static void shuffleSort(long[] arr) {
            Shuffler.shuffle(arr);
            Arrays.sort(arr);
        }

        private Utils() {}
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        private String next() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    //noinspection CallToPrintStackTrace
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int[] nextIntArray(int n) {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++) { a[i] = nextInt(); }
            return a;
        }

        long[] nextLongArray(int n) {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++) { a[i] = nextLong(); }
            return a;
        }
    }
}
