import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] total = new int[n]; //나이 배열
        String[] array = new String[n]; //이름 배열
        int[] sub = new int[n]; //나이 배열 서브

        for (int i = 0 ; i < n ; i++) {
            String name = sc.next();
            int d = sc.nextInt();
            int m = sc.nextInt();
            int y = sc.nextInt();
            total[i] = (y * 365) + (m * 31) + d;
            array[i] = name;
            sub[i] = (y * 365) + (m * 31) + d;
        }

        Arrays.sort(total); // 오름차순 정렬

        for (int i = 0 ; i < n ; i++) {
            if (total[n-1] == sub[i]) { //나이 배열 제일 큰 값과 같으면
                System.out.println(array[i]); //나이 제일 어린 사람
            } else if (total[0] == sub[i]) { //나이 배열 제일 작은 값과 같으면
                System.out.println(array[i]); //나이 제일 많은 사람
            }
        }
    }
}