#include<bits/stdc++.h>
#define int long long
using namespace std;
char buf[1<<23],*p1=buf,*p2=buf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline int read(){
int f=1,x=0;char ch=getchar();
while(!isdigit(ch)){if(x<0) f=-1;ch=getchar();}
while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
return x*f;
}
inline void print(int x){
if(x<0) {putchar('-'),x=-x;}
if(x>9) print(x/10);
putchar(x%10+'0');
}
int n;string s;
int a[20010],cnt;
string w[1005];
bool cmp(string x,string y){
if(x.size()>y.size()) return 0;
else if(x.size()<y.size()) return 1;
else{
for(int i=0;i<s.size();i++){
if(x[i]>y[i]) return 0;
else if(x[i]<y[i]) return 1;
}
}
}
signed main(){
ios::sync_with_stdio(false);
cin>>n;
bool flag=0;
for(int i=1;i<=n;i++){
cin>>s;int j=0;
while(j<s.size()){
bool flag=0;
string t="";
while(s[j]>='0'&&s[j]<='9'){
t+=s[j];
flag=1;
j++;
}
if(flag){
int tmp=0;
while(t[tmp]=='0'&&tmp<t.size()-1){
tmp++;
}
++cnt;
for(int k=tmp;k<t.size();k++){
w[cnt]+=t[k];
}
}
while(s[j]<'0'||s[j]>'9') j++;
}
int k=0;
}
sort(w+1,w+1+cnt,cmp);
for(int i=1;i<=cnt;i++){
cout<<w[i]<<'\n';
}
return 0;
}