#include<stdio.h>
#include<string.h>
int compare( char *a, char *b)
{
if(strlen(a)>strlen(b)) return 1;
else if(strlen(a)==strlen(b)) return strcmp(a,b);
else return -1;
}
int main()
{
char c2[20];
char c[7000000];
char a[2000000][3];
int n,i,ten,p,j,count;
while(1)
{
n=0;
ten=1;
gets( c2 );
if(c2[0]=='0')
return 0;
i=0;
while(c2[i]>='0'&&c2[i]<='9') i++;
for(;i>0;i--)
{
n+=(c2[i-1]-48)*ten;
ten*=10;
}
gets( c );
p=0;
for(i=0;i<n;i++)
{
while(c[p]<'0'||c[p]>'9') p++;
count=0;
while(c[p]>='0'&&c[p]<='9')
{
count++;
p++;
}
if(count==1)
{
a[i][0]=c[p-1];
a[i][1]=0;
}
if(count==2)
{
a[i][0]=c[p-2];
a[i][1]=c[p-1];
a[i][2]=0;
}
}
qsort(a,n,3,compare);
for(i=0;i<n;i++)
printf("%s ",a[i]);
printf("\n");
}
}