#include <iostream>
#include <stdio.h>
using namespace std;
struct food {
	char fn[21];
	int g;
	int s;
};
int f[10],an[10],m;
food fd[10],sf;

int ans(int n,int s) {
	int i;
	if (n==-1) { for (i=m-1;i>=0;i--) cout << fd[an[i]].fn << endl; return 1;}
	for (i=m-1;i>=0;i--) {
		if (f[i]==0 && fd[i].s>=s-fd[i].g) {
			f[i]=1; an[n]=i;
			if (ans(n-1,s-fd[i].g)==1) return 1; 
			f[i]=0;
		}
	}
	return 0;
}

int main() {
	int i,j,s;
	while(cin >> m) {
		if (m==0) break;
		for (i=0,s=0;i<m;i++) { f[i]=0; cin >> fd[i].fn >> fd[i].g >> fd[i].s;  s+=fd[i].g;}
		for (i=1;i<m;i++) for (j=0;j<m-i;j++) if (fd[j].g>fd[j+1].g) { sf=fd[j]; fd[j]=fd[j+1]; fd[j+1]=sf;}
        ans(m-1,s);		
	}
 return 0;
 }