#include <cstdio>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;

bool com(string a,string b){
    return a.size()<b.size();
}

int main() {
    int n;
    string str;
    vector<string> vec;
    while (cin >> n) {
        vec.clear();
        n=n+1;
        while (n--) {
            getline(cin, str);
            if (str == "stop") break;
            vec.push_back(str);
        }
        int u = vec.size();
        sort(vec.begin(), vec.end(),com);
        cout<<vec[0];
        for (int i = 1; i <u; i++) cout << vec[i] << endl;
    }

}
// 64 位输出请用 printf("%lld")