#include
using namespace std;
class node{
public:
long data;
node* next;
node(long d){
data=d;
next=NULL; // do not forget this
}
};
void print(node* head){
while(head!=NULL){
cout<data<<" ";
head=head->next;
}
}
void insertAtTail(node*& head,long data){
if(head==NULL){
head= new node(data);
return ;
}
node* temp=head;
while(temp->next!=NULL){
temp=temp->next;
}
temp->next=new node(data);
return;
}
node* mergesortedlist(node* a,node* b){
if(a==NULL)
return b;
else if(b==NULL)
return a;
node* c=NULL;
if(a->data<=b->data){
c =a;
c->next=mergesortedlist(a->next,b);
}
else {
c=b;
c->next=mergesortedlist(a,b->next);
}
return c;
}
int main() {
node* head1=NULL;
nodehead2=NULL;
int t;
cin>>t;
while(t–){
long n,m;
long data;
cin>>n;
while(n–)
{
cin>>data;
insertAtTail(head1,data);
}
cin>>m;
while(m–)
{
cin>>data;
insertAtTail(head2,data);
}
node ans=mergesortedlist(head1,head2);
print(ans);
cout<<endl;
}
return 0;
}