#include <stdio.h>
#include <string.h>

enum /*untagged*/ { AbeforeB = -1, AequalsB = 0, AafterB = 1 };

int tailored_strcmp(const char *a, const char *b) {
    static char baseorder[] = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz";
    //if a or b is the empty string
    if (*a == 0) return AbeforeB;
    if (*b == 0) return AafterB;
    int lena = strlen(a);
    int lenb = strlen(b);
    char *pa = strchr(baseorder, *a);
    char *pb = strchr(baseorder, *b);
    if (pa == NULL) return lena < lenb ? AbeforeB : AafterB;
    if (pb == NULL) return lena < lenb ? AbeforeB : AafterB;
    if (pa == pb) {
    	//need to check second letter
        char *ppa = strchr(baseorder, a[1]);
        char *ppb = strchr(baseorder, b[1]);
        if (ppa == NULL) return lena < lenb ? AbeforeB : AafterB;
        if (ppb == NULL) return lena < lenb ? AbeforeB : AafterB;
        if (ppa == ppb) return lena < lenb ? AbeforeB : AafterB;
        return ppa < ppb ? AbeforeB : AafterB;
    }
    return pa < pb ? AbeforeB : AafterB;
}


int main(void) {
    int i = 0, j = 0, count;
    char str[25][25], temp[25];
    while (1) {
        gets(str[i]);
        if (str[i][0] == '0') break;
        i++;
    }
    count = i;
    for (i = 0; i < count; i++)  {
        for (j = i + 1; j < count; j++) {
            if (tailored_strcmp(str[i], str[j]) > 0) {
                strcpy(temp, str[i]);
                strcpy(str[i], str[j]);
                strcpy(str[j], temp);
            }
        }
    }
    for (i = 0; i < count; i++) {
        printf("[%s] ", str[i]);
    }

    return 0;
}
