import java.util.*;
class Node{
int data;
Node left;
Node right;
}
class BST{
public Node insert(int[] arr,int lo ,int hi ){
if(lo > hi){
return null;
}
int mid = (lo + hi)/2;
Node node = new Node();
node.data = arr[mid];
node.left = insert(arr, lo, mid-1);
node.right = insert(arr, mid+1,hi);
return node;
}
public static void preorder(Node node){
if(node == null){
return;
}
System.out.print(node.data +" ");
preorder(node.left);
preorder(node.right);
}
}
public class Main {
public static void main(String args[]) {
BST bst = new BST();
Scanner sc = new Scanner(System.in);
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();
}
int k1 = sc.nextInt();
int k2 = sc.nextInt();
Arrays.sort(arr);
Node nn = bst.insert(arr,0, n-1);
System.out.print("# Preorder : ");
bst.preorder(nn);
System.out.println();
System.out.print("# Nodes within range are : ");
for(int i = 0; i< n; i++){
if(arr[i] >= k1 && arr[i] <= k2)
System.out.print(arr[i]+" ");
}
}
}
}