#include
#include
#include
#include
using namespace std;
bool compare(string a,string b)
{
if(a[0]==b[0])
{
if(a.length()<b.length())
{
if(a==b.substr(0,a.length()))
return 1;
else
return lexicographical_compare(a.begin(), a.end(), b.begin(), b.end());
}
else
{
if(b==a.substr(0,b.length()))
return -1;
else
return lexicographical_compare(a.begin(), a.end(), b.begin(), b.end());
}
}
else
{
return lexicographical_compare(a.begin(), a.end(), b.begin(), b.end());
}
}
int main()
{
int test;
cin>>test;
string s[test],buff;
getline(cin,buff);
for(int i=0;i<test;i++)
{
getline(cin,s[i]);
}
sort(s,s+test,compare);
for(int i=0;i<test;i++)
{
cout<<s[i]<<endl;
}
return 0;
}