Please check my code
#include
#include
using namespace std;
int main(){
int t;
cin>>t;
for(int i=0; i<t; i++){
int n;
cin>>n;
list l1;
for(int i=0; i<n; i++){
int t;
cin>>t;
l1.push_back(t);
}
int m;
cin>>m;
list l2;
for(int i=0; i<m; i++){
int t;
cin>>t;
l2.push_back(t);
}
list l3;
while(!l1.empty() and !l2.empty()){
if(l1.front()<l2.front()){
l3.push_back(l1.front());
l1.pop_front();
}
else{
l3.push_back(l2.front());
l2.pop_front();
}
}
if(l1.empty()){
while(!l2.empty()){
l3.push_back(l2.front());
l2.pop_front();
}
}
else{
while(!l1.empty()){
l3.push_back(l1.front());
l1.pop_front();
}
}
for(auto l:l3){
cout<<l<<" ";
}
}
return 0;
}