#include<stdio.h>
#include<stdlib.h>
struct Node{
    int data;
    struct Node* next;
};

struct Node*createNode(int value){
    struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
    newNode->data=value;
    newNode->next=NULL;
    return newNode;
}
struct Node* insertEnd(struct Node* head,int value){
    struct Node* newNode = createNode(value);
    if(head == NULL){
        return newNode;
    }
    struct Node* temp = head;
    while (temp->next !=NULL){
        temp=temp->next;
    }
    temp->next = newNode;
    return head;
}
struct Node* mergeSortedLists(struct Node* list1,struct Node* list2){
    struct Node dummy;
    struct Node* tail = &dummy;
    dummy.next = NULL;
    
    while(list1 !=NULL && list2 !=NULL){
        if(list1->data <= list2->data){
            tail->next = list1;
            list1=list1->next;
        }else{
            tail->next=list2;
            list2=list2->next;
        }
        tail=tail->next;
    }
    if(list1 !=NULL){
        tail->next = list1;
    }else{
        tail->next= list2;
    }
    return dummy.next;
}
void printList(struct Node* head){
    struct Node* temp=head;
    while(temp != NULL){
        printf("%d",temp->data);
        if(temp->next !=NULL){
            printf(" ");
        }
        temp = temp->next;
    }
}
void freeList(struct Node* head){
    struct Node* temp;
    while(head !=NULL){
        temp=head;
        head=head->next;
        free(temp);
    }
}
int main(){
    int n1,n2,value;
    struct Node* list1=NULL;
    struct Node* list2=NULL;
    
    scanf("%d",&n1);
    for(int i=0;i<n1;i++){
        scanf("%d",&value);
        list1=insertEnd(list1,value);
    }
    scanf("%d",&n2);
    for(int i=0;i<n2;i++){
        scanf("%d",&value);
        list2=insertEnd(list2,value);
    }
    struct Node* mergedList=mergeSortedList(list1,list2);
    printList(mergedList);
    freeList(mergedList);
    return 0;
}