public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(bf.readLine());
String[][] arr = new String[n][2];
for (int i = 0; i < n; i++){
StringTokenizer st = new StringTokenizer(bf.readLine());
arr[i][0] = st.nextToken();
arr[i][1] = st.nextToken();
}
Arrays.sort(arr, (o1, o2) -> {
if(o1[0] == o2[0]){
return compare(o1[1],o2[1]);
}else{
return Integer.compare(Integer.parseInt(o1[0]), Integer.parseInt(o2[0]));
}
});
for (String[] i : arr){
System.out.println(i[0] + " " + i[1]);
}
}