Start: Jan, 04, 2017 19:40:00
2016年秋季学期程序设计基础期末考试
End: Jan, 04, 2017 21:40:00
Time elapsed:
Time remaining:

Problem_ID: D
Result: Accepted
Time: 603ms
Memory: 1724kB
Author: SuperBlade
In contest: 1084

#include<cstdio>
#include <string>
#include <string.h>
#include <cmath>
#include<stack>
#include <queue>
#include <map>
#include <vector>
#include <cstdlib>
#include <iostream>
#include<algorithm>
using namespace std;
typedef long long ll;


ll gcd(ll x, ll y)
{
	return y == 0? x:gcd(y, x%y);	
}

ll lcm(ll x, ll y)
{
	return x/gcd(x,y)*y;
}

ll pow_mod(ll a,ll n, ll mod)
{
	ll res=1;
	while(n)
	{
		if(n&1)res= res*a%mod;
		a=a*a%mod;
		n>>=1;
	}
	return res;
}

/*
input:1 0.0001
output:0.36788
*/
double fun(double x[10])
{
	int i;
	long t;
	double avg=0,sum=0;
	for(int i =0 ;i < 10;i++)
	{
		sum+=x[i];
	}

	avg=sum*100;
	t=avg;
	avg=(double)t/100;
	return avg;
}


struct node 
{

	string name;
	int a,b;
};
bool com(const node &x,const node &y)
{
	return x.a+x.b>y.a+y.b;
}

int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		int n;
		scanf("%d",&n);
		vector<node> v;
		for(int i =0;i<n;i++)
		{
			node tmp;
			cin>>tmp.name>>tmp.a>>tmp.b;
			v.push_back(tmp);
		}
		sort(v.begin(),v.end(),com);

		for(int i =0;i<v.size();i++)
		{
			cout<<v[i].name<<endl;
		}

	}
}