#include<stdio.h>
#define N 100000

int patition(int [],int,int);
void quickSort(int[],int,int);

int A[N];
char B[N];

int main(){

  int i,left=1,right;
  char c[N];
  scanf("%d",&right);
  for(i=0;i<right;i++){
    scanf("%c%c%d",&B[i],&c[i],&A[i]);
  }

  quickSort(A,left,right);

  for(i=0;i<right;i++){
    printf("%c %d\n",B[i],A[i]);
  }
  

  return 0;
}

int partition(int A[],int left,int right){

  int i,j,x=0,s=0;
  char c;
  x=A[right-1];
  i=left-1;

  for(j=left;j<right-1;j++){
    if(A[j]<=x){
     
      s=A[i];
      A[i]=A[j];
      A[j]=s;

      c=B[i];
      B[i]=B[j];
      B[j]=c;

      i++;
    }
  }

  s=A[i];
  A[i]=A[right-1];
  A[right-1]=s;

  c=B[i];
  B[i]=B[right-1];
  B[right-1]=c;

 
  return i;
}

void quickSort(int A[],int left,int right){
  
  int q=0,s=0;
  
  if(left < right){
    if(left < q){ 
      q = partition(A,left,right);
      quickSort(A,left,q-1);
    }
  } 
  if(left < right){
    if(right > q){      
      quickSort(A,q+1,right);   
    }
    //fprintf( stderr, "Check\n" );
  }
  
  
}