// editor4
#include<stdio.h>
#include<stdlib.h>
struct node{
    int data;
    struct node*prev,*next;
};
struct node* createnode(int data)
{
    struct node*newnode=(struct node*)malloc(sizeof(struct node));
    newnode->data=data;
    newnode->prev=newnode->next=NULL;
    return newnode;
}
void insertend(struct node**head,int data)
{
    struct node*newnode=createnode(data);
    if(*head==NULL){
        *head=newnode;
        return;
    }
    struct node*temp=*head;
    while(temp->next) temp=temp->next;
    temp->next=newnode;
    newnode->prev=temp;
}
struct node*merge(struct node*head1,struct node*head2)
{
    if(!head1)return head2;
    if(!head2)return head1;
    struct node*result=NULL;
    if(head1->data<=head2->data){
        result=head1;
        result->next=merge(head1->next,head2);
        if(result->next) result->next->prev=result;
    }
    return result;
}
void printlist(struct node*head)
{
    struct node*temp=head;
    while(temp!=NULL)
    {
        printf("%d",temp->data);
        temp=temp->next;
    }
    printf("\n");
}
int main()
{
    int n1,n2,val;
    scanf("%d",&n1);
    if(n1<=0)
    {
        printf("Invalid input\n");
        return 0;
        
    }
    struct node*head1=NULL;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&val);
head1=inserend(head1,val);
}
scanf("%d",n2);
if(n2<=0)
{
    printf("Invalid input\n");
    return 0;
}
struct node*head2=NULL;
for(int i=0;i<n2;i++)
{
    scanf("%d",&val);
    head2=insertend(head2,val);
    
}
struct node mergedhead=mergelists(head1,head2);
printlist(mergedhead);
return 0;
}