#include<stdio.h>
struct Card{
  char suit;
int value;
};
 struct Card A[100001];
int q;

int Partition(int p,int r){
  int i,j,x;
  struct Card key;

  x=A[r].value;
  i=p-1;

  for(j=p;j<r;j++){
    if(A[j].value<=x){
      i=i+1;
      key=A[i];
      A[i]=A[j];
      A[j]=key;
    }
  }
  key=A[i+1];
  A[i+1]=A[r];
  A[r]=key;

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

int main(){
  int n,i;
  char ch,ch2;
 
  scanf("%d",&n);
	
	for(i=1;i<=n;i++) scanf("%c%c%d%c",&A[i].suit,&ch2,&A[i].value,&ch);
		

  Quicksort(1,n);

  for(i=1;i<=n;i++) printf("%c %d\n",A[i].suit,A[i].value);
  
  return 0;
}