#include
using namespace std;
class node{
public:
int data;
node *next;
node(int value){
data=value;
next=NULL;
}
};
void insertAt_tail(node*&head,int value){
if(head==NULL){
head= new node(value);
return;
}
node n=new node(value);
nodetemp=head;
while(temp->next!=NULL){
temp=temp->next;
}
temp->next=n;
}
void print(node *head){
while(head!=NULL){
cout<data<<" ";
head=head->next;
}
}
node * merge(node * head1,node * head2){
if(head1==NULL) return head2;
if(head2==NULL) return head1;
node * c;
if(head1->data data){
c=head1;
c->next=merge(head1->next,head2);
}
else{
c=head2;
c->next=merge(head1,head2->next);
}
return c;
}
int main(){
int t;
cin>>t;
while(t–){
node *head1=NULL;
node *head2=NULL;
int n1,n2,ele;
cin>>n1;
for(int i=0;i<n1;i++){
cin>>ele;
insertAt_tail(head1,ele);
}
cin>>n2;
for(int i=0;i<n2;i++){
cin>>ele;
insertAt_tail(head2,ele);
}
node * head=merge(head1,head2);
print(head);
}
return 0;
}