只90分
type node=record
su,nu,ch:longint;
end;
var i,j,n,a,b,c:longint;
s:array[0..100000] of node;
procedure qsort(l,r:longint);
var i,j:longint;
k:node;
begin
i:=l;j:=r;k:=s[i];
while i<j do begin
while (i<j)and(k.su>s[j].su)or((k.su=s[j].su)and(k.ch>s[j].ch))or((k.su=s[j].su)and(k.ch=s[j].ch)and(k.nu<s[j].nu)) do dec(j);
if i<j then begin s[i]:=s[j];inc(i);end;
while (i<j)and(k.su<s[i].su)or((k.su=s[i].su)and(k.ch<s[i].ch))or((k.su=s[i].su)and(k.ch=s[i].ch)and(k.nu>s[i].nu)) do inc(i);
if i<j then begin s[j]:=s[i];dec(j);end;
end;
s[i]:=k;
if l<i-1 then qsort(l,i-1);
if i+1<r then qsort(i+1,r);
end;
begin
readln(n);
for i:=1 to n do begin
readln(a,b,c);
s[i].su:=a+b+c;s[i].ch:=a;s[i].nu:=i;
end;
qsort(1,n);
for i:=1 to 5 do
writeln(s[i].nu,' ',s[i].su);
end.