#include<iostream>
#include<cstring>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
#define maxn 1010
int f(char s[],char s1[])
{
    if(strlen(s)!=strlen(s1))
    {
        if(strlen(s)>strlen(s1))
            return 1;
        else return 2;
    }
    for(int i=0; i<strlen(s); i++)
    {
        if(s[i]>s1[i])
            return 1;
        if(s[i]<s1[i])
            return 2;
    }
    return 0;
}
char str[105][1010];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        memset(str,0,sizeof(str));
        getchar();
        for(int i=0; i<n; i++)
            gets(str[i]);
        for(int k=0; k<n-1; k++)
            for(int p=0; p<n-1-k; p++)
                if(f(str[p],str[p+1]))
                {
                    char tmp[1010];
                    strcpy(tmp,str[p]);
                    strcpy(str[p],str[p+1]);
                    strcpy(str[p+1],tmp);
                }
        for(int i=0; i<n; i++)
            puts(str[i]);
    }
    return 0;
}
 
#include<iostream>
#include <string.h>
#include <string>
#include <algorithm>
using namespace std;
#define maxn 105
int i,n;
string str[maxn];
bool cmp(string s1, string s2)
{
    if(s1.size() == s2.size())
        return s1 < s2;
    else
        return s1.size() < s2.size();
}
int main()
{
    while(cin >> n)
    {
        for(i = 0 ; i < n; i++)
            cin >> str[i];
        sort(str, str+n ,cmp);
        for (i = 0; i < n; i++)
            cout << str[i] << endl;
    }
    return 0;
}