Why is my solution wrong?

I have done lexicographical sorting of the numbers in descending order and printed them.Sample test case is passing but why are none of the hidden ones passing?

Just a simple sort will not do.
Consider a case:
1
2
98 9

Expected O/p:
998

Your O/p:
989

There must be a custom compare function something like this:
bool mycompare(string a,string b)
{
string ab=a+b;
string ba=b+a;
return ab>ba;
}

I think i got it but i thought that when i compare lex 9 with 98 ,

it would be like 9==9 and then 9<8 so 9>98

i have done this but it is still not passing any of the hidden test case, i cant figure out why?
this is my code:-
#include
#include
#include
#include
using namespace std;

bool compare(string a, string b){
string ab=a+b;
string ba=b+a;
return ab>ba;
}

int main(){
int t;
cin>>t;
for(int i=0;i<t;i++){
int n;
cin>>n;
cin.get();
string a[1000];
for(int j=0;j<n;j++){
cin>>a[j];
}
sort(a,a+n,compare);
a[n]=’\0’;
for(int j=0;j<n;j++){
cout<<a[j];
}
}
return 0;
}

After printing the result of each test case, include an endl.