import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
@SuppressWarnings("resource")
Scanner input = new Scanner(System.in);
int num = Integer.parseInt(input.nextLine());
Map<String,Integer> map = new HashMap<>();
for(int i=0;i<num;i++) {
String order = input.nextLine().toLowerCase().trim();
String[] arr = order.split(" ");
if (map.containsKey(arr[0])){
if (map.get(arr[0]) < Integer.parseInt(arr[1])){
map.put(arr[0],Integer.parseInt(arr[1]));
}
}else{
map.put(arr[0],Integer.parseInt(arr[1]));
}
}
for(Map.Entry<String,Integer> m : map.entrySet()){
System.out.println(m.getKey() + " " + m.getValue());
}
input.close();
}
}