import java.util.Scanner;
public class Main {
private Node head;
private Node tail;
private int size;
private class Node {
int data;
Node next;
Node(int data, Node next) {
this.data = data;
this.next = next;
}
}
public Main() {
this.head = null;
this.tail = null;
this.size = 0;
}
public int size() {
return this.size;
}
public void addLast(int data) {
Node node = new Node(data, null);
if (this.size() == 0) {
this.head = node;
this.tail = node;
} else {
this.tail.next = node;
this.tail = node;
}
this.size++;
}
public static void display(Node temp) {
while (temp != null) {
System.out.print(temp.data + " ");
temp = temp.next;
}
}
static Node merge(Node h1, Node h2) {
if (h1 == null) {
return h2;
}
if (h2 == null) {
return h1;
}
if (h1.data < h2.data) {
h1.next = merge(h1.next, h2);
return h1;
} else {
h2.next = merge(h1, h2.next);
return h2;
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int T = scanner.nextInt();
Main list1 = new Main();
Main list2 = new Main();
while (T-- > 0) {
int S1 = scanner.nextInt();
for (int i = 0; i < S1; i++) {
list1.addLast(scanner.nextInt());
}
int S2 = scanner.nextInt();
for (int i = 0; i < S2; i++) {
list2.addLast(scanner.nextInt());
}
Node head = merge(list1.head, list2.head);
display(head);
System.out.println();
}
}
}