#include <bits/stdc++.h>
#define MAX 1000
using namespace std;

bool cmp(vector<int> a, vector<int> b) {
    int lena = a.size(), lenb = b.size();
    if (lena < lenb)
        return true;
    else if (lena == lenb) {
        for (int i = 0; i < lena; i++) {
            if (a[i] < b[i])
                return true;
            else if(a[i] == b[i])
                continue;
            else
                return false;
        }
    }
    return false;
}

int main() {
    int n;
    string tmp;
    vector<vector<int>> data;
    vector<int> arr;
    while (cin >> n) {
        for (int i = 0; i < n; i++) {
            cin >> tmp;
            for (int j = 0; j < tmp.size(); j++)
                arr.push_back(tmp[j] - '0');
            data.push_back(arr);
            arr.clear();
        }

        sort(data.begin(), data.end(), cmp);

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < data[i].size(); j++) {
                cout << data[i][j];
            }
            cout << endl;
        }
    }
}