import java.util.*;
public class Main
{
public static class Node
{
int data;
Node next;
}
public static class LinkedList
{
private Node head;
private Node tail;
private int size;
public void addLast(int item)
{
Node nn=new Node();
nn.data=item;
if(size>0)
tail.next=nn;
if(size==0)
head=tail=nn;
else
tail=tail.next;
size++;
}
}
public static void main(String[] args)
{
Scanner sc=new Scanner (System.in);
int t=sc.nextInt();
while(t!=0)
{
LinkedList list1=new LinkedList();
LinkedList list2=new LinkedList();
int size1=sc.nextInt();
for(int i=0;i<size1;i++)
{
list1.addLast(sc.nextInt());
}
int size2=sc.nextInt();
for(int i=0;i<size2;i++)
{
list2.addLast(sc.nextInt());
}
Node l1=list1.head;
Node l2=list2.head;
while(l1!=null && l2!=null)
{
if(l1.data<=l2.data)
{
System.out.print(l1.data+" ");
l1=l1.next;
}
else
{
System.out.print(l2.data+" ");
l2=l2.next;
}
}
if(l1!=null)
{
while(l1!=null)
{
System.out.print(l1.data+" ");
l1=l1.next;
}
}
else if(l2!=null)
{
while(l2!=null)
{
System.out.print(l2.data+" ");
l2=l2.next;
}
}
t--;
}
}
}