import java.io.*; import java.util.*; /** * Root the tree and check for distance 3 using a small number of constant time * checks using ancestry information. * Time complexity: O(n) * * @author Finn Lidbetter */ public class youbethejudge_finn { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); while(t-- > 0) { int n = Integer.parseInt(br.readLine()); int[] permutation = new int[n]; int[] parent = new int[n]; Node[] nodes = new Node[n]; for (int i=0; i adj; public Node(int idd) { id = idd; adj = new ArrayList<>(); } }