// https://practice.geeksforgeeks.org/problems/print-binary-tree-levels-in-sorted-order/0

import java.util.*;
import java.lang.*;
import java.io.*;
class Solution
 {
	public static Scanner sc = new Scanner(System.in);
	public static void main (String[] args){
        int t = sc.nextInt();

        while((t--)>0){
            int n = sc.nextInt();
            int[] arr = new int[n];
            for(int i=0;i<n;i++)
                arr[i]=sc.nextInt();

            
            
            for(int i=0;i<n/2;i++){
                if((2*i+1)<n && (2*i+2)<n){
                    System.out.println(" PARENT : " + arr[i] 
                    + " LEFT CHILD [" + ((2 * i) + 1) + "] : " + arr[(2 * i) + 1] 
                    + " RIGHT CHILD :" + arr[(2 * i) + 2]); 
                }
            }
        }
        
    }
}
@@ -454,32 +454,55 @@
 );%0A%0A            
+printLevelOrder(arr,n);
 %0A            %0A  
@@ -498,48 +498,479 @@
     
+%7D%0A
     
+%7D%0A
 %0A    
-        for(int i=0;i%3Cn/2;i++)%7B
+private static void printLevelOrder(int%5B%5D arr, int n) %7B%0A        if(arr.length == 0)%0A            return;%0A%0A        LinkedList%3CInteger%3E queue = new LinkedList%3CInteger%3E();%0A        SortedSet%3CInteger%3E pq = new TreeSet%3CInteger%3E();%0A%0A        queue.addLast(0);%0A        queue.addLast(null);%0A%0A        while(!queue.isEmpty())%7B%0A            Integer index = queue.getFirst();%0A            queue.removeFirst();%0A%0A            if(index!=null)%7B%0A                pq.add(arr%5Bindex%5D);
 %0A   
@@ -990,93 +990,199 @@
 if((
+(
 2*i
-+1)%3Cn && (2*i+2)%3Cn)%7B%0A                    System.out.println(%22 PARENT : %22 + arr%5Bi%5D 
+ndex)+1)%3Cn)%7B%0A                    queue.addLast(((2*index)+1));%0A                %7D%0A%0A                if(((2*index)+2)%3Cn)%7B%0A                    queue.addLast(((2*index)+2));%0A                %7D%0A
 %0A   
@@ -1186,32 +1186,34 @@
             
+%7D%0A
         
 + %22 LEFT CHI
@@ -1204,70 +1204,159 @@
     
-+ %22 LEFT CHILD %5B%22 + ((2 * i) + 1) + %22%5D : %22 + arr%5B(2 * i) + 1%5D 
+    else%7B%0A                if(pq.isEmpty())%0A                    break;%0A                for(int val:pq)%7B%0A                    System.out.print(val + %22 %22);
 %0A   
@@ -1372,52 +1372,85 @@
     
+%7D%0A%0A
     
-+ %22 RIGHT CHILD :%22 + arr%5B(2 * i) + 2%5D
+            System.out.println();%0A                queue.addLast(null
 );
- 
 %0A   
@@ -1454,33 +1454,43 @@
                 
-%7D
+pq.clear();
 %0A            %7D%0A 

level sorted order given an array