#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>
int main() {
int n;
while (scanf("%d", &n) != EOF) {
struct {
char s[11];
int ma;
int ch;
int en;
int sum;
}st[105];
for (int i = 1; i <= n; i++) {
scanf("%s %d %d %d", st[i].s, &st[i].ch, &st[i].ma, &st[i].en);
st[i].sum = st[i].ch + st[i].ma + st[i].en;
}
for (int i = 1; i < n; i++) {
for (int j = i + 1; j <= n; j++) {
if ((st[i].sum < st[j].sum)||(st[i].sum==st[j].sum&&st[i].s[0]>st[j].s[0])) {
st[104] = st[j];
st[j] = st[i];
st[i] = st[104];
}
}
}
for (int i = 1; i <= 3; i++) {
int len = strlen(st[i].s);
for (int j = 0; j < len; j++)printf("%c", st[i].s[j]);
printf(" ");
printf("%d\n", st[i].sum);
}
printf("\n");
for (int i = 1; i < n; i++) {
for (int j = i + 1; j <= n; j++) {
if ((st[i].ch < st[j].ch) || (st[i].ch == st[j].ch && st[i].s[0] > st[j].s[0])) {
st[104] = st[j];
st[j] = st[i];
st[i] = st[104];
}
}
}
for (int i = 1; i <= 3; i++) {
int len = strlen(st[i].s);
for (int j = 0; j < len; j++)printf("%c", st[i].s[j]);
printf(" ");
printf("%d\n", st[i].ch);
}
printf("\n");
for (int i = 1; i < n; i++) {
for (int j = i + 1; j <= n; j++) {
if ((st[i].ma < st[j].ma) || (st[i].ma == st[j].ma && st[i].s[0] > st[j].s[0])) {
st[104] = st[j];
st[j] = st[i];
st[i] = st[104];
}
}
}
for (int i = 1; i <= 3; i++) {
int len = strlen(st[i].s);
for (int j = 0; j < len; j++)printf("%c", st[i].s[j]);
printf(" ");
printf("%d\n", st[i].ma);
}
printf("\n");
for (int i = 1; i < n; i++) {
for (int j = i + 1; j <= n; j++) {
if ((st[i].en < st[j].en) || (st[i].en == st[j].en&& st[i].s[0] > st[j].s[0])) {
st[104] = st[j];
st[j] = st[i];
st[i] = st[104];
}
}
}
for (int i = 1; i <= 3; i++) {
int len = strlen(st[i].s);
for (int j = 0; j < len; j++)printf("%c", st[i].s[j]);
printf(" ");
printf("%d\n", st[i].en);
}
printf("\n");
}return 0;
}