#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
using namespace std;
int main()
{
    int n;
    string str;
    while(cin >> n){
        getchar();
        vector<string> vec;
        while(n--){
            getline(cin,str);
            if(str == "stop")
                break;
            vec.push_back(str);
        }
        sort(vec.begin(),vec.end(),[](const string a,const string b){
            return a.length() < b.length();
        });
        for(auto it : vec)
            cout << it << endl;
    }
}