using System;
public class GFG 
{
	static public void Main () 
	{
        int T = int.Parse(Console.ReadLine());
		while(T>0)
		{
			int N = int.Parse(Console.ReadLine());
				
			string [] numbers = new string[N];
			string [] keys    = new string[N];

			char [] c = new char[1]{' '};
			
			numbers = Console.ReadLine().TrimEnd(' ').Split(c,N,StringSplitOptions.RemoveEmptyEntries);
				
			for(int i=0;i<N;i++)
			{
				string s = numbers[i];
				int l = s.Length;
				char s1 = s[0];
					
			    if(l==1)
					keys[i]=s+s1+s1;
				else if(l==2)
					keys[i]=s+s1;
				else
					keys[i]=s;
			}
				
			Array.Sort(keys, numbers);
			N--;
				
			bool sw = true;
			
			while (sw)
			{
				sw = false;
				for(int i=0;i<N;i++)
				{
				    bool sd = false;
				    
					if(keys[i]==keys[i+1] && numbers[i]!=numbers[i+1])
					{
						if(numbers[i].Length>1 && numbers[i+1].Length>1)
						{
							char c1 = numbers[i][0];
							char c2 = numbers[i][1];
								
							if(numbers[i].Length>numbers[i+1].Length)
							{
								if(c1>c2)
								    sd = true;
							}
							else if(c1<c2)
								sd = true;
								
							if(sd)
							{
								string w = numbers[i];
								numbers[i] = numbers[i+1];
								numbers[i+1] = w;
								sw = true;
							}
						}
					}
				}
			}
				
			string r = "";
				
			if(numbers[N]=="0")
				r = "0";
			else
			{
				for(int i=N;i>-1;i--)
				{
					r+=numbers[i];
				}
			}
				
			Console.WriteLine(r);
				
			T--;
		}
	}
}