#include<stdio.h>

int Partition(int, int);
void Quicksort(int, int);

char A[100000][5];
int main(){
    int n,p = 0,i;
    
    scanf("%d",&n);
    for(i=0; i<n; i++){
        scanf("%s",A[i]);
    }
    
    Quicksort(p,n);
    
    for(i=0; i<n; i++){
    printf("%s\n",A[i]);
    }
    return 0;
}

int Partition(int p, int r){
    int x;
    char temp[5];
    int i,j;
    char str[2];
    str[1] = '\0';

    str[0] = A[r][2];
    x = atoi(str);
    
    i = p-1;
    for(j=p; j<r-1; j++){
        str[0] = A[j][2];
        if(atoi(str) <= x){
            i = i+1;
            strcpy(temp,A[i]);
            strcpy(A[i],A[j]);
            strcpy(A[j],temp);
        }
    }
    strcpy(temp,A[i+1]);
    strcpy(A[i+1],A[r]);
    strcpy(A[r],temp);
    
    return i+1;
}

void Quicksort(int p, int r){
    int q;    
    
    if(p < r){
        q = Partition(p,r);
        Quicksort(p,q-1);
        Quicksort(q+1,r);
    }
}