import java.util.*;
public class Main {
private static int[] arr;
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
int t = sc.nextInt();
while(t>0){
// Create a new array. The user enters the size
int[] arr = new int[sc.nextInt()];
// Get the value of each element in the array
for(int i = 0; i < arr.length; i++)
arr[i] = sc.nextInt();
t--;
}
BST bst=new BST(arr);
bst.preOrder();
}
public static class BST{
public class Node{
int data;
Node left;
Node right;
}
private Node root;
public BST(int[] arr){
this.root=construct(arr,0,arr.length-1);
}
private Node construct(int[] arr,int lo, int hi){
int mid=(lo+hi)/2;
Node nn=new Node();
nn.data=mid;
nn.left=construct(arr,lo,mid-1);
nn.right=construct(arr,mid+1,hi);
return nn;
}
public void preOrder(){
this.preOrder(this.root);
}
private void preOrder(Node node){
if(node==null){
return;
}
System.out.print(node.data+" ");
preOrder(node.left);
preOrder(node.right);
}
}
}