#include <cstdio>
#include <cstring>

class candidate {
private:
public:
    int id;
    char name[11];
    int score1;
    int score;
    candidate();
    ~candidate();
    void readCandidate();
    void printCandidate();
    void printId();
};

candidate::candidate() {
    id = 0;
    score1 = 0;
    score = 0;
    memset(name, 0, sizeof(name));
}

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);
}

void countingSort(candidate *cptr, int n, int k, int pos, int (*func)(candidate, int), bool reverse) {
    candidate *cptr2 = new candidate[n];
    int *count = new int[k];
    memset(count, 0, sizeof(int) * k);
    for (int i = 0; i < n; i++) {
        count[func(cptr[i], pos)]++;
    }
    if (reverse) {
        for (int i = 1; i < k; i++) {
            count[i] += count[i - 1];
        }
    } else {
        for (int i = k - 2; i >= 0; i--) {
            count[i] += count[i + 1];
        }
    }
    for (int i = n - 1; i >= 0; i--) {
        cptr2[--count[func(cptr[i], pos)]] = cptr[i];
    }
    memcpy(cptr, cptr2, sizeof(candidate) * n);
    delete[] cptr2;
    delete[] count;
}

void radixSort(candidate *cptr, int n) {
    int pow = 1;
    for (int i = 0; i < 6; i++) {
        countingSort(
            cptr, n, 10, pow, [](candidate c, int i) { return c.id / i % 10; }, true);
        pow *= 10;
    }
    for (int i = 9; i >= 0; i--) {
        countingSort(
            cptr, n, 128, i, [](candidate c, int i) { return c.name[i] - '\0'; }, true);
    }
    pow = 1;
    for (int i = 0; i < 3; i++) {
        countingSort(
            cptr, n, 10, pow, [](candidate c, int i) { return c.score1 / i % 10; }, false);
        pow *= 10;
    }

    pow = 1;
    for (int i = 0; i < 3; i++) {
        countingSort(
            cptr, n, 10, pow, [](candidate c, int i) { return c.score / i % 10; }, false);
        pow *= 10;
    }
}

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

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

    radixSort(cptr, n);

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