public class mergetwosortedLL {
private class node {
int data;
node next;
public int size;
}
private node head;
private node tail;
private int size;
public void display() {
node temp = this.head;
while (temp != null) {
System.out.print(temp.data + ", ");
temp = temp.next;
}
}
public void addlast(int item) {
node nn = new node();
nn.data = item;
nn.next = null;
if (this.size >= 1) {
this.tail.next = nn;
}
if (this.size == 0) {
this.head = nn;
this.tail = nn;
this.size++;
} else {
this.tail = nn;
this.size++;
}
}
public static void main(String[] args) {
Scanner scn=new Scanner(System.in);
int t=scn.nextInt();
for (int i=0;i<t;i++) {
int n1=scn.nextInt();
mergetwosortedLL list1=new mergetwosortedLL();
for(int j=0;j<n1;j++) {
int a=scn.nextInt();
list1.addlast(a);
}
int n2=scn.nextInt();
mergetwosortedLL list2=new mergetwosortedLL();
for(int j=0;j<n2;j++) {
int b=scn.nextInt();
list2.addlast(b);
}
mergetwosortedLL list=mergetwosortLL( list1,list2);
list.display();
}
}
public static mergetwosortedLL mergetwosortLL(mergetwosortedLL list1,mergetwosortedLL list2) {
mergetwosortedLL merged=new mergetwosortedLL();
node one= list1.head;
node two=list2.head;
while (one !=null && two!=null) {
if (one.data <two.data) {
merged.addlast(one.data);
one=one.next;
}
else {
merged.addlast(two.data);
two=two.next;
}
}
if (one ==null) {
while (two!=null) {
merged.addlast(two.data);
two=two.next;
}
}
if (two ==null) {
while (one!=null) {
merged.addlast(one.data);
one=one.next;
}
}
return merged;
}
}