function main(input){
  const N = input.split("\n")[0];
  var arr =[];
  
  var retsu=input.split("\n");
  
  for(var i=0; i<N; i++){
    var temp=[]
    temp.push(retsu[i+1].split(" ")[0]);
    temp.push(parseInt(retsu[i+1].split(" ")[1], 10));
    arr.push(temp)
  }

  arr.sort(function(a,b){
    if(a[0]>b[0]) return 1;
    if(a[0]<b[0]) return -1;
    if(a[1]>b[1]) return -1;
    if(a[1]<b[1]) return 1;
  });

  console.log(arr);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));