import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int i=1 ; i<=t ; i++) {
int n=sc.nextInt();
int arr[]=new int[n];
for(int j=0 ; j<n ; j++)
arr[j]=sc.nextInt();
Arrays.sort(arr);
Main mn = new Main();
BST bst=mn.new BST(arr);
int m=sc.nextInt();
for(int j=1 ; j<=m ; j++) {
bst.remove(sc.nextInt());
}
bst.preOrder();
}
}
public class BST {
private class Node{
int data;
Node left=null;
Node right=null;
}
private Node root;
ArrayList<Integer> al = new ArrayList<>();
public BST (int [] inorder) {
this.root=construct(inorder , 0 , inorder.length-1);
}
private Node construct(int [] inorder , int start , int end) {
if(start>end) return null;
if(start==end) {
Node base = new Node();
base.data=inorder[start];
al.add(base.data);
return base;
}
int mid=(start+end)/2;
Node node = new Node();
node.data=inorder[mid];
al.add(node.data);
node.left=construct(inorder , start , mid-1);
node.right=construct(inorder , mid+1 , end);
return node;
}
public void preOrder() {
this.preOrder(this.root);
System.out.println();
}
private void preOrder(Node node) {
if(node==null) return;
System.out.print(node.data+" ");
preOrder(node.left);
preOrder(node.right);
}
public int max() {
return max(this.root);
}
private int max(Node node) {
if(node.right==null) return node.data;
max(node.right);
return 0;
}
public void remove(int item) {
remove(this.root , null , false , item);
}
private void remove(Node node , Node parent , boolean isleftchild , int item) {
// left child ke liye true and right child ke liye false rakha hai
// when given node is not present in the tree , then return
if(node==null) return;
// first reach on the node from where it is to be removed
if(item<node.data) {
remove(node.left , node , true , item);
}
// first reach on the node from where it is to be removed
else if(item>node.data) {
remove(node.right , node , false , item);
}
// after reaching on a node to be removed
else if(item==node.data) {
// 4 cases are to be taken care
// removing element from array list
int k=0;
while(al.get(k)!=item)
k++;
al.remove(k);
// when node is leaf node
if(node.left==null && node.right==null) {
if(isleftchild) {
parent.left=null;
} else {
parent.right=null;
}
}
// when there is tree on right side of a node only
if(node.left==null && node.right!=null) {
if(isleftchild) {
parent.left=node.right;
} else {
parent.right=node.right;
}
}
// when there is a tree on a left side of a tree only
if(node.left!=null && node.right==null) {
if(isleftchild) {
parent.left=node.left;
} else {
parent.right=node.left;
}
}
// when there is a tree on both sides of a node
if(node.left!=null && node.right!=null) {
// Note : In case of node with 2 children, consider its inorder successor as its replacement.
int arr[] = new int[al.size()];
for(int l=0 ; l<al.size() ; l++)
arr[l]=al.get(l);
Arrays.sort(arr);
this.root=construct(arr , 0 , arr.length-1);
// // find max element on a left side of a node
// int max=max(node.left);
//
// // replace node with the max element of a left side of a node
// node.data=max;
//
// // remove that max element from left tree of a node
// remove(node.left , node , true , max);
//
}
}
}
}
}