#include <cstdio>
#include <cstring>

class candidate {
private:
    int id;
    char name[11];
    int score1;
    int score;

public:
    candidate();
    ~candidate();
    void readCandidate();
    void printCandidate();
    void printId();
    bool operator<(const candidate &c);
};

candidate::candidate() {
    id = 0;
    score1 = 0;
    score = 0;
}

candidate::~candidate() {
}

void candidate::readCandidate() {
    int score2 = 0;
    for (int j = 0; j < 6; j++) {
        this->id = this->id * 10 + getchar() - '0';
    }
    getchar();
    int j = 0;
    while ((this->name[j] = getchar()) != ' ') {
        j++;
    }
    this->name[j] = '\0';
    char ch;
    while ((ch = getchar()) != ' ') {
        this->score1 = this->score1 * 10 + ch - '0';
    }
    while ((ch = getchar()) != '\n') {
        score2 = score2 * 10 + ch - '0';
    }
    this->score = this->score1 + score2;
}

void candidate::printCandidate() {
    printf("%d %s %d %d\n", this->id, this->name, this->score1, this->score);
}

void candidate::printId() {
    printf("%06d\n", this->id);
}

bool candidate::operator<(const candidate &c) {
    if (this->score != c.score) {
        return this->score < c.score;
    } else if (this->score1 != c.score1) {
        return this->score1 < c.score1;
    } else if (strcmp(this->name, c.name) != 0) {
        return strcmp(this->name, c.name) > 0;
    } else {
        return this->id > c.id;
    }
}

void quickSort(candidate *cptr, int left, int right) {
    if (left >= right) {
        return;
    }
    int i = left, j = right;
    candidate pivot = cptr[left];
    while (i < j) {
        while (i < j && cptr[j] < pivot) {
            j--;
        }
        while (i < j && pivot < cptr[i]) {
            i++;
        }
        if (i < j) {
            candidate temp = cptr[i];
            cptr[i] = cptr[j];
            cptr[j] = temp;
        }
    }
    quickSort(cptr, left, j - 1);
    quickSort(cptr, i + 1, right);
}

int main(void) {
    int n;
    scanf("%d", &n);
    getchar();

    candidate *cptr = new candidate[n];
    for (int i = 0; i < n; i++) {
        cptr[i].readCandidate();
    }

    quickSort(cptr, 0, n - 1);

    for (int i = 0; i < n; i++) {
        cptr[i].printId();
    }
    delete[] cptr;
    return 0;
}