import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { private static Map factorials = new HashMap(); private static BigInteger getFactorial(int n) { if(factorials.containsKey(n)) return factorials.get(n); BigInteger fact = BigInteger.ONE; for(int i = 2 ; i <= n ; i++) fact = fact.multiply(BigInteger.valueOf(i)); factorials.put(n, fact); return fact; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int q = in.nextInt(); for(int a0 = 0; a0 < q; a0++){ int n = in.nextInt(); if(n == 1) System.out.println("1"); else System.out.println(((long)java.lang.Math.pow(n,n-2)+1)%663224321); } } }