#include<iostream>
#include<string>
#include<list>
#include<map>
using namespace std;

const int MAX_F = 15;

class tabemono{
private:
	int No;
	int W;
	int S;
public:
	int retS();
	int retW();
	int retNo();
	void setNo(int no);
	void setW(int w);
	void setS(int s);
};

int tabemono::retS(){
	return S;
}

int tabemono::retW(){
	return W;
}

int tabemono::retNo(){
	return No;
}

void tabemono::setNo(int no){
	No = no;
}

void tabemono::setW(int w){
	W = w;
}

void tabemono::setS(int s){
	S = s;
}

int main(){
	int n;
	while(cin >>n){
		if(n == 0) break;
		
		list<tabemono> hukuro;
		multimap<int, int, greater<int> > tmpmap;
		string food[MAX_F];
		int weight[MAX_F], strenght[MAX_F], sum = 0;
		for(int i = 0; i < n; i++){
			cin >>food[i] >>weight[i] >>strenght[i];
			sum += weight[i];
			tmpmap.insert( map<int, int, greater<int> >::value_type(strenght[i], i) );
		}
		
		map<int, int, greater<int> >::iterator itm;
		for(itm = tmpmap.begin(); itm != tmpmap.end(); itm++){
			tabemono t;
			t.setNo((*itm).second);
			t.setW(weight[(*itm).second]);
			t.setS(strenght[(*itm).second]);
			hukuro.push_back(t);
		}
		
		while(hukuro.empty() != 1){
			int max = -1;
			list<tabemono>::iterator maxit = hukuro.begin();
			list<tabemono>::iterator itl;
			if(hukuro.size() != 1){
				for(itl = hukuro.begin(); itl != hukuro.end(); itl++){
					int tmp = (*itl).retW();
 					if((*itl).retS() < (sum - tmp)){
						itl--;
						break;
					}
					if(tmp > max){
						max = tmp;
						maxit = itl;
					}
				}
			}
			cout <<food[(*maxit).retNo()] <<endl;
			sum -= (*maxit).retW();
			hukuro.erase(maxit);
		}
		
	}
	return 0;
}