#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <sstream>

using namespace std;

int main(){
	
	while(true){
		
		int n;
		
		cin >> n;
		
		if(n == 0){
			break;
		}
		
		string name[10];
		int index[10], index_ans[10];
		double w[10], s[10];
		
		for(int i = 0; i < n; i++){
			cin >> name[i] >> w[i] >> s[i];
			index[i] = i;
		}
		
		double G_min = 100000;
		
		do{
			double weight_sum = 0;
			for(int i = 0; i < n; i++){
				if(weight_sum > s[index[i]]){
					break;
				}
				weight_sum += w[index[i]];
				if(i == n - 1){
					int G_cur = 0;
					for(int j = 0; j < n; j++){
						G_cur += w[index[j]] * (n - j);
					}
					if(G_cur < G_min){
						G_min = G_cur;
						for(int j = 0; j < n; j++){
							index_ans[j] = index[j];
						}
					}
				}
			}
		}while(next_permutation(index, index + n));
		
		for(int i = 0; i < n; i++){
			cout << name[index_ans[n - i - 1]] << endl;
		}
		
	}
	
	return 0;
}