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

int tailored_strcmp(const char *a, const char *b) {
    static char baseorder[] = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz";
    if (*a && *b) {
        //both strings have at least 1 character
        char *pa = strchr(baseorder, *a);
        if (!pa) return -1;
        char *pb = strchr(baseorder, *b);
        if (!pb) return 1;
        if (pa == pb) {
            //need to check second character of a and b
            char *ppa = strchr(baseorder, a[1]);
            if (!ppa) return -1;
            char *ppb = strchr(baseorder, b[1]);
            if (!ppb) return 1;
            if (ppa < ppb) return -1;
            if (ppa > ppb) return 1;
            return 0; // ignore anything beyond the 2nd character
        } else {
            if (pa < pb) return -1;
            return 1;
        }
    } else {
        //at least one string is the empty string
        if (*a == *b) return 0; // both empty strings
        if (*a) return -1;      // b empty string, comes before a
        return 1;               // a empty string
    }
}


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;
}
