#include<bits/stdc++.h>
#define maxn (1005)
using namespace std;
struct Student
{
int Math,Chinese,English;
int total;
int num;
bool operator < (const Student &other) const
{
if(total != other.total)
return total > other.total;
else
return Chinese > other.Chinese;
}
}student[maxn];
int main()
{
int n;
cin >> n;
for(int i = 0;i < n;i++)
{
student[i].num = i+1;
cin >> student[i].Chinese >> student[i].Math >> student[i].English;
student[i].total = student[i].Chinese + student[i].Math + student[i].English;
}
sort( student , student + n );
for(int i = 0;i < n;i++)
{
cout << student[i].num << ' ' << student[i].total << endl;
}
return 0;
}