typedef struct stu
{
int cls;
int id;
char name[20];
int y, m, d;
} Stu;
bool cmp(const Stu &p, const Stu &q)
{
if (p.y == q.y)
{
if (p.m == q.m)
{
if (p.d == q.d)
return strcmp(p.name, q.name) < 0;
else
return p.d < q.d;
}
else
return p.m < q.m;
}
return p.y < q.y;
}
int main()
{
int n, k, i, j;
cin >> n;
vector<Stu> student;
for (i = 0; i < n; i++)
{
cin >> k;
for (j = 0; j < k; j++)
{
Stu stu;
cin >> stu.name >> stu.y >> stu.m >> stu.d;
stu.id = j + 1;
stu.cls = i + 1;
student.push_back(stu);
}
}
sort(student.begin(), student.end(), cmp);
cout << endl;
for (i = 0; i < student.size(); i++)
{
cout << student[i].name << " "
<< student[i].cls << " "
<< student[i].id << endl;
}
return 0;
}