// editor5
#include<stdio.h>
#include<stdlib.h>
struct Node{
    int data;
    struct Node*next;
    
};
struct Node*createNode(int data)
{
    struct Node*newNode=(struct Node*)malloc(sizeof(struct Node));
    newNode->data=data;
    newNode->next=NULL;
    return newNode;
    
}
struct Node*buidList(int n){
    if(n<=0) return NULL;
    struct Node*head=NULL,*temp=NULL;
    for(int i=;i<n;i++)
    {
        int val;
        scanf("%d",&val);
        struct Node*newNode=createNode(val);
        if(head==NULL) head=newNode;
        else temp->next=newNode;
        temp=newNode;
    }
    return head;
}
void printList(struct Node*head)
{
    struct Node*temp=head;
    while(temp!=NULL)
    {
        printf("%d",temp->data);
        temp=temp->next;
    }
    printf("\n");
    
}
struct NOde*mergeLists(struct Node*list1,struct Node*list2)
{
    struct Node*mergedHead=NULL,*mergedTail=NULL;
    struct Node*temp=list1;
    while(temp!=NULL){
        struct Node*newNode=createNode(temp->data);
        if(mergedHead==NULL)mergedHead=newNode;
        else mergedTail->next=newNode;
        mergedTail=newNode;
        temp=temp->next;
    }
    temp=list2;
    while (temp!=NULL)
    {
        struct Node*newNode=createNode(temp->data);
        if(mergedHead==NULL)mergedHead=newNode;
        else mergedTail->next=newNode;
        mergedTail=newNode;
        temp=temp->next;
        
    }
    return mergedHead;
}
int main(){
    int n,m;
    scanf("%d",&n);
    if(n<=0)
    {
        printf("Invalid input\n");
        return 0;
    }
    struct Node*list1=buildList(n);
    scanf("%d",&m);
    if(m<=0)
    {
        printf("Invalid input\n");
        return 0;
        
    }
    struct Node*list2=buildList(m);
    printf("\n");
    printList(list1);
    printf("\n");
    printList(list2);
    printf("\n");
    struct Node*merged=mergeLists(list1,list2);
    printList(merged);
    return 0;
}