#include
using namespace std;
class node{
public:
node* next;
int data;
node(int d){
data = d;
next = NULL;
}
};
node* sortedMerge(node* a,node* b){
node* result = NULL;
if(a==NULL){
return b;
}
if(b==NULL){
return a;
}
if(a->data <= b->data){
result = a;
result->next = sortedMerge(a->next,b);
}
else if(b->data <= a->data){
result = b;
result->next = sortedMerge(a,b->next);
}
return result;
}
// node* midPoint(node*&head){
// node* fast = head;
// node* slow = head;
// while(fast!=NULL && fast->next!=NULL){
// fast = fast->next->next;
// slow = slow->next;
// }
// return slow;
// }
void print(node*&head){
node* temp = head;
while(temp!=NULL){
cout<data<<" ";
temp=temp->next;
}
}
void insertAtTail(node*&head,int d){
if(head==NULL){
head = new node(d);
return ;
}
node* temp = head;
while(temp->next!=NULL){
temp=temp->next;
}
temp->next = new node(d);
return;
}
void buildList(node*&head,int n){
node* temp = head;
int data=0;
while(n>0){
cin>>data;
insertAtTail(head,data);
n–;
}
}
int main() {
int t,n,m;
node* head = NULL;
node* head2 = NULL;
cin>>t;
while(t–){
cin>>n;
buildList(head,n);
cin>>m;
buildList(head2,m);
node* c = sortedMerge(head,head2);
print©;
}
return 0;
}