import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            String []a = new String[n];
            String []b = new String[n];
            String []c = new String[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.next();
                b[i] = in.next();
                c[i] = in.next();
            }
            String min = b[0];
            int index1 = 0;
            for (int i = 1; i < n; i++) {
                if (min.compareTo(b[i])>0) {
                    min = b[i];
                    index1 = i;
                }
            }
            System.out.print(a[index1] + " ");
            String max=c[0];int index2=0;
            for (int i = 1; i < n; i++) {
                if ( max.compareTo(c[i])<0) {
                    max = c[i];
                    index2 = i;
                }
            }
            System.out.print(a[index2] );
            System.out.println();
        }
    }
}