import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String maxInfo = "";
String minInfo = "";
int max = -1;
int min = 101;
for(int i = 0 ; i < n ; i++) {
String name = sc.next();
String course = sc.next();
int score = sc.nextInt();
if(max <= score) {
max = score;
maxInfo = name + " " + course;
}
if(min >= score) {
min = score;
minInfo = name + " " + course;
}
}
System.out.println(maxInfo);
System.out.println(minInfo);
}
}