#include <stdio.h>
#include <stdlib.h>
typedef struct node{
    int data;
    struct node *next;
    struct node *prev;
}a;
a *head=NULL,*tail,*head1=NULL,*tail1;
void create (int num){
    a *newNode=(a*)malloc(sizeof(a));
    newNode->data=num;
    newNode->next=NULL;
    newNode->prev=NULL;
    if(head==NULL){
        head=newNode;
        tail=newNode;
    }
    else{
        newNode->prev=tail;
        tail->next=newNode;
        tail=newNode;
    }
}
void create1 (int num1){
    a *newNode1=(a*)malloc(sizeof(a));
    newNode1->data=num1;
    newNode1->next=NULL;
    newNode1->prev=NULL;
    if(head1==NULL){
        head1=newNode1;
        tail1=newNode1;
    }
    else{
        newNode1->prev=tail1;
        tail1->next=newNode1;
        tail1=newNode1;
    }
}
void display(){
    a *i,*j;
    for(i=head;i!=NULL;i=i->next){
        for(j=head1;j!=NULL;j=i->next){
            if(i->data>j->data){
                printf("%d",j-data);
            }
            else{
                printf("%d",i->data);
            }
        }
    }
}
int main(){
    int size1,size2,num,num2;
    scanf("%d",&size1);
    for(int i=0;i<size1;i++){
        scanf("%d",&num);
        create(num);
    }
    scanf("%d",&size2);
       for(int i=0;i<size2;i++){
        scanf("%d",&num2);
        create(num2);
    }
    display();
    return 0;
}