#include <iostream>
#include <algorithm>
using namespace std;

struct line {
    string words;
    int len;
    bool operator< (const line& t) const {
        return len < t.len;
    }
};
int main() {
    int n;
    while (scanf("%d\n",&n)!=EOF) {
        line* arr = new line[n];
        string str;
        int index = 0;
        while (getline(cin, str) && str != "stop"&&str!=" ") {
            line l;
            l.words = str;
            l.len = str.size();
            arr[index++] = l;
            if (index == n) break;
        }
        sort(arr, arr + index);
        for (int i = 0; i < index; i++) cout << arr[i].words << endl;
    }
    return 0;
}