import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.NoSuchElementException; class Main { public static void main(String[] args) { new Main().run(); } void run() { FastScanner sc=new FastScanner(); int T=sc.nextInt(); PrintWriter pw=new PrintWriter(System.out); int sumn=0; while (T-->0) { int N=sc.nextInt(); sumn+=N; if (!(3 <= N && N <= 5e5)) throw new AssertionError(); int[] P=new int[N]; boolean[] vis=new boolean[N]; for (int i=0;i5e5) throw new AssertionError(); pw.close(); } long solve(int N, int[] P) { int[] sum=new int[N+1]; for (int i=0;i+1 set, int mod) { DSU dsu=new DSU(mod); for (int i=1;i