import std.stdio;

struct Food {
	string f;
	int w, s;
	bool used;
	int opCmp(ref const Food f) const{
		return f.w > w;
	}
}

Food[10] f;

void main(){
	int n, sum;
	while (readf("%d\n", &n), n) {
		sum = 0;
		foreach (i; 0..n) {
			readf("%s %d %d\n", &f[i].f, &f[i].w, &f[i].s);
			f[i].used = false;
			sum += f[i].w;
		}
		f[0..n].sort;
		foreach (j; 0..n) {
			foreach (i; 0..n) {
				if (f[i].s >= sum - f[i].w && !f[i].used) {
					writeln(f[i].f);
					sum -= f[i].w;
					f[i].used = true;
					break;
				}
			}
		}
	}
}