import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) {
try {
BufferedReader bufferedReader =new BufferedReader(new InputStreamReader(System.in, Charset.defaultCharset()));
List<Student> studentList = new ArrayList<>();
int count = Integer.parseInt(bufferedReader.readLine());
for (int i = 0;i<count;i++) {
String[] read = bufferedReader.readLine().split(" ");
int chinese = Integer.parseInt(read[1]);
int maths = Integer.parseInt(read[2]);
int english = Integer.parseInt(read[3]);
Student student = new Student() {
@Override
public String name() {
return read[0];
}
@Override
public int chinese() {
return chinese;
}
@Override
public int maths() {
return maths;
}
@Override
public int english() {
return english;
}
@Override
public int total() {
return chinese+maths+english;
}
};
studentList.add(i,student);
}
for (int i = 0;i<count;i++) {
Student student = studentList.get(i);
for (int j = 0;j<count;j++) {
Student target = studentList.get(j);
if (Math.abs(student.total() - target.total()) <= 10) {
if (Math.abs(student.chinese() - target.chinese()) > 5) {
continue;
}
if (Math.abs(student.maths() - target.maths()) > 5) {
continue;
}
if (Math.abs(student.english() - target.english()) > 5) {
continue;
}
if (student.name().equals(target.name())) {
continue;
}
if (student.targeted.contains(target.name())) {
continue;
}
System.out.println(student.name()+" "+target.name());
target.targeted.add(student.name());
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
public interface Student {
String name();
int chinese();
int maths();
int english();
int total();
List<String> targeted = new ArrayList<>();
}
}