AC
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new java.util.Scanner(System.in);
int n = sc.nextInt();
String[][] stu = new String[n][4];
for (int i = 0; i < n; i++) {
for (int j = 0; j < 4; j++) {
stu[i][j] = sc.next();
}
}
for (int i = 0; i < n; i++) {
for (int j = i+1; j < n; j++) {
if (Math.abs(Integer.parseInt(stu[i][1]) - Math.abs(Integer.parseInt(stu[j][1]))) <= 5 &&
Math.abs(Integer.parseInt(stu[i][2]) - Math.abs(Integer.parseInt(stu[j][2]))) <= 5 &&
Math.abs(Integer.parseInt(stu[i][3]) - Math.abs(Integer.parseInt(stu[j][3]))) <= 5 &&
Math.abs((Integer.parseInt(stu[i][1]) + Integer.parseInt(stu[i][2]) + Integer.parseInt(stu[i][3])) - (Integer.parseInt(stu[j][1]) + Integer.parseInt(stu[j][2]) + Integer.parseInt(stu[j][3]))) <= 10
) {
System.out.println(stu[i][0] + " "+ stu[j][0]);
}
}
}
}
}