using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.IO; using System.Reflection; using static System.Math; using System.Numerics; using System.Threading; using System.Runtime.CompilerServices; using System.Diagnostics; //using nint=System.Int32; static class Program{ const long inf=long.MaxValue>>1; const int mod=(int)1e9+7;//998244353; static void Main(){ Sc sc=new Sc(); //var (n,m)=sc.Tp2(); var t=sc.I; StringBuilder sb=new StringBuilder(); for(int i = 0;i[n+1]; var lib=new List[n+1]; Uf uf=new Uf(n+1); lia[1]=new List(); lib[1]=new List(); for(int j = 2;j<=n;j++) { lia[j]=new List(); lib[j]=new List(); for(int k = j<<1;k<=n;k+=j) {uf.Union(j,k);} } for(int j = 1;j<=n;j++) { lia[uf.Root(j)].Add(a[j]); lib[uf.Root(j)].Add(b[j]); } var bo=true; for(int j = 1;j<=n&&bo;j++) { lia[j].Sort(); lib[j].Sort(); for(int k = 0;k(int n,Func f){var a=new T[n];for(int i=0;i(int n,Func f){var a=new T[n];for(int i=0;i(int n,Func f){var a=new T[n];for(int i=0;i(int n,Func f){var a=new T[n];for(int i=0;i(){var s=Console.ReadLine().Split();return (Ct(s[0]),Ct(s[1]));} public (T,T,T) Tp3(){var s=Console.ReadLine().Split();return (Ct(s[0]),Ct(s[1]),Ct(s[2]));} public (T,T,T,T) Tp4(){var s=Console.ReadLine().Split();return (Ct(s[0]),Ct(s[1]),Ct(s[2]),Ct(s[3]));} public (T,T,T,T,T) Tp5(){var s=Console.ReadLine().Split();return (Ct(s[0]),Ct(s[1]),Ct(s[2]),Ct(s[3]),Ct(s[4]));} public (T1,T2) Tp2(){var s=Console.ReadLine().Split();return (Ct(s[0]),Ct(s[1]));} public (T1,T1,T2) Tp3(){var s=Console.ReadLine().Split();return (Ct(s[0]),Ct(s[1]),Ct(s[2]));} private T Ct(string s){return (T)Convert.ChangeType(s,typeof(T));} }