#include <fstream>
#include <map>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    ifstream in("names.in");
    ofstream out("names.out");
    int n;
    in >> n;
    vector<vector<string> > v(n, vector<string>(3));
    map<string, int> counts;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            in >> v[i][j];
            counts[v[i][j]]++;
        }
    }
    for (int i = 0; i < n; i++)
        if (counts[v[i][0]] > 1)
            v[i] = {v[i][2], v[i][0], v[i][1]};
    sort(v.begin(), v.end());
    for (auto row: v)
        out << row[0] << " " << row[1] << " " << row[2] << "\n";
}
