#include <stdio.h>
#include <string.h>
#define MAX_NAMES 20
#define NAME_SIZE 64

int readLine(char text[], size_t capacity) {
    if (fgets(text, (int)capacity, stdin) == NULL) return 0;
    size_t length = strlen(text);
    if (length > 0 && text[length - 1] == '\n') text[--length] = '\0';
    else if (!feof(stdin)) {
        int ch = getchar();
        if (ch != '\n' && ch != EOF) return 0;
    }
    if (length > 0 && text[length - 1] == '\r') text[length - 1] = '\0';
    return 1;
}

int main(void) {
    char names[MAX_NAMES][NAME_SIZE], temporary[NAME_SIZE];
    int n, ch;
    if (scanf("%d", &n) != 1 || n < 1 || n > MAX_NAMES) {
        puts("Invalid input."); return 1;
    }
    while ((ch = getchar()) != '\n' && ch != EOF) { }
    for (int i = 0; i < n; ++i) {
        if (!readLine(names[i], sizeof names[i]) || names[i][0] == '\0') {
            puts("Invalid input."); return 1;
        }
    }
    for (int pass = 0; pass < n - 1; ++pass)
        for (int j = 0; j < n - 1 - pass; ++j)
            if (strcmp(names[j], names[j + 1]) > 0) {
                strcpy(temporary, names[j]);
                strcpy(names[j], names[j + 1]);
                strcpy(names[j + 1], temporary);
            }
    puts("Sorted names:");
    for (int i = 0; i < n; ++i) puts(names[i]);
    return 0;
}
