#include
using namespace std;
class node{
public:
int data;
node* next;
node(int data){
this->data=data;
this->next=NULL;
}
};
void mergesorted(node* &first,node* &second){
node* curr1=first;
node* curr2=second;
node* next=curr1->next;
node* next2=curr2->next;
while(next!=NULL && curr2!=NULL){
if((curr1->data <= curr2->data) && (curr2->data <= curr1->next->data)){
curr1->next=curr2;
next2=curr2->next;
curr2->next=next;
curr1=curr2;
curr2=next2;
}
else{
curr1=next;
next=curr1->next;
if(next==NULL){
curr1->next=curr2;
}
}
}
}
node* merge2list(nodefirst ,nodesecond){
if(first==NULL){
return second;
}
if(second==NULL){
return first;
}
if(first->datadata){
mergesorted(first,second);
}
else
{
mergesorted(second,first);
}
return first;
}
node* print(node* head){
if(head==NULL){
return head;
}
node* temp=head;
while(temp!=NULL){
cout<data<<" ";
temp=temp->next;
}
return head;
}
void insertathead(node* &head,node* &tail,int data){
if(head==NULL && tail==NULL){
node* n=new node(data);
head=n;
tail=n;
return;
}
node* n=new node(data);
tail->next=n;
tail=n;
return;
}
int main() {
int test;
cin>>test;
node* tail1=NULL;
node* tail2=NULL;
node* head1=NULL;
node* head2=NULL;
while(test–){
int n1;
cin>>n1;
for(int i=0;i<n1;i++){
int element;
cin>>element;
insertathead(head1,tail1,element);
}
int n2;
cin>>n2;
for(int i=0;i<n2;i++){
int element;
cin>>element;
insertathead(head2,tail2,element);
}
}
node* head3=merge2list(head1,head2);
print(head3);
return 0;
}