#include
using namespace std;
class node{
public:
int data;
node* next;
node(int d){
data=d;
next=NULL;
}
};
void insertAtHead(node*&head,int data){
node* n=new node(data);
n->next=head;
head=n;
}
void display(node* head){
node* temp=head;
while(temp!=NULL){
cout<<temp->data<<" ";
temp=temp->next;
}
cout<<endl;
}
void insertAtTail(node* &head,int data){
if(head==NULL){
insertAtHead(head,data);
return;
}
node* tail = head;
while(tail->next!=NULL){
tail = tail->next;
}
node* n= new node(data);
tail->next = n;
}
node* findMid(node* head){
node* fast=head;
node* slow=head;
while(fast!=NULL && fast->next!=NULL){
slow=slow->next;
fast=fast->next->next;
}
return slow;
}
node* merge(node* &a, node* &b){
if(a==NULL){
return b;
}
if(b==NULL){
return a;
}
node* c;
if(a->data <= b->data){
c=a;
c->next=merge(a->next, b);
}
else{
c=b;
c->next=merge(a, b->next);
}
return c;
}
int main()
{
int t;
cin>>t;
while(t–){
int n1;
cin>>n1;
node* head1=NULL;
while(n1–)
{
int data;
cin>>data;
insertAtTail(head1,data);
}
int n2;
cin>>n2;
node* head2=NULL;
while(n2–)
{
int data;
cin>>data;
insertAtTail(head2,data);
}
//display(head);
node* h=merge(head1,head2);
display(h);
return 0;
}
}