#include<bits/stdc++.h>
using namespace std;
bool cmp(string s1,string s2)
{
	string s3=s1+s2,s4=s2+s1;
	return s3<=s4;
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,i;
		cin>>n;
		string str[n];
		for(i=0;i<n;i++)
		cin>>str[i];
		sort(str,str+n,cmp);
		string ans="";
		for(i=n-1;i>=0;i--)
		ans+=str[i];
		cout<<ans<<endl;
	}
}