#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

const int INF = 1 << 24;
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

typedef unsigned long long ull;
typedef std::pair<int,int> P;

struct Food{
    std::string name;
    ull w, s;
};

const int MAX_N = 10;
int N;
std::vector<Food> F;
int order[MAX_N], fact[11];

int main(){
    fact[0] = 1;
    FOR(i, 1, 11){
        fact[i] = fact[i-1] * i;
    }

    std::cin >> N;
    
    REP(i, N){
        std::string name;
        ull w, s;
        std::cin >> name >> w >> s;
        
        F.push_back({name, w, s});
    }

    REP(i, N){
        order[i] = i;
    }
    
    ull min_cost = INF;
    int min_order[MAX_N];
    REP(_, fact[N]){
        // for(int i=0;i<N;i++){
        //     printf("%d, ", order[i]);
        // }
        // puts("");

        bool f = true;
        ull cost = 0, sum = 0;
        REP(i, N){
            int index = order[i];
            if(sum <= F[index].s);
            else{f = false;}

            cost += (N-i) * F[index].w;
            sum += F[index].w;
        }
        //std::cout << cost << std::endl;

        if(f && min_cost > cost){
            min_cost = cost;
            std::copy(order, order+N, min_order);
        }

        std::next_permutation(order, order+N);
    }

    //std::cout << min_cost << std::endl;
    for(int i=N-1;i>=0;i--){
        int index = min_order[i];
        std::cout << F[index].name << std::endl;
    }
}