The code goes here:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
bool cmp(ll a, ll b){
string s1 = to_string(a) + to_string(b);
string s2 = to_string(b) + to_string(a);
//cout << s1 << " " << s2 << “\n”;
int n = s1.length();
for(int i = 0; i < n; i++){
if(int(s1[i] - ‘0’) > int(s2[i] - ‘0’)){
return int(s1[i] - ‘0’) > int(s2[i] - ‘0’);
}
else if(int(s1[i] - ‘0’) < int(s2[i] - ‘0’)){
return int(s1[i] - ‘0’) < int(s2[i] - ‘0’);
}
}
return true;
}
int main() {
ll t;
cin >> t;
while(t–){
ll n;
cin >> n;
vector v;
for(ll i = 0; i < n; i++){
ll x;
cin >> x;
v.push_back(x);
}
sort(v.begin(), v.end(), cmp);
string s = “”;
for(ll i = 0; i < n; i++){
s = s + to_string(v[i]);
}
cout << s << “\n”;
}
return 0;
}