#include
using namespace std;
class node{
public:
int data;
node* next;
node(int d){
data=d;
next=NULL;
}
};
void insertattail(node* & root,int data){
if(root==NULL){
root=new node(data);
return;
}
node* temp=root;
while(temp->next!=NULL){
temp=temp->next;
}
temp->next=new node(data);
return;
}
void print(node* head){
if(head==NULL){
return;
}
while(head->next != NULL){
cout<data<<" ";
head=head->next;
}
cout<data;
}
node merge(node a,node* b){
if(a==NULL){
return b;
}
if(b==NULL){
return a;
}
node* c;
if(a->datadata){
c=a;
c->next=merge(a->next,b);
}
else{
c=b;
c->next=merge(a,b->next);
}
return c;
}
int main() {
int t;
cin>>t;
while(t–){
node* a=NULL;
int n;
cin>>n;
while(n–){
int data;
cin>>data;
insertattail(a,data);
}
node *b =NULL;
int m;
cin>>m;
// print (a);
while(m–){
int data;
cin>>data;
insertattail(b,data);
}
// print(b);
node* c=merge(a,b);
print©;
}
return 0;
}
sample pass but not testcases