//制約侵害のcheck import java.util.Arrays; import java.util.Scanner; import java.math.*; class Main { public static void main(String[] args) { new Main().run(); } void run() { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); if (!(1<=N&&N<=1000)) throw new AssertionError(); long[] p = new long[N]; for (int i = 0; i < N; ++i) { p[i] = sc.nextLong(); if (!(2<=p[i]&&p[i]<=1e9)||!BigInteger.valueOf(p[i]).isProbablePrime(20)) throw new AssertionError(); System.out.println(solve(p[i])); } } long solve(long p) { if (p!=2) return 1-2*p+p*p; else return 2; } long pow(long a, long n, long mod) { long ret = 1; for (; n > 0; n >>= 1, a = a * a % mod) { if (n % 2 == 1) ret = ret * a % mod; } return ret; } void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }