#include<bits/stdc++.h>
using namespace std;
int me[10],rigidity[10],n;
char str[10][21];
void serch(int num,int now,int sum,int point,int co)
{
    if(num==0)return;
    else if(n==now){
        rigidity[point]=-10000;
        cout<<str[point]<<endl;;
        serch(num-1,0,sum-me[point],0,0);
    }
    else if(sum-me[now]<=rigidity[now]&&co==0)serch(num,now+1,sum,now,1);
    else if(sum-me[now]<=rigidity[now]&&me[point]<me[now])serch(num,now+1,sum,now,1);
    else serch(num,now+1,sum,point,co);
}
int main()
{
    while(cin>>n,n){
        int sum=0;
        for(int i=0;i<n;i++){
            cin>>str[i]>>me[i]>>rigidity[i];
            sum+=me[i];
        }
        serch(n,0,sum,0,0);
    }

}