#include <iostream>
using namespace std;
int a[101], b[101], c[101], d[101];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i] >> c[i];
d[i] = a[i] * 3600 + b[i] * 60 + c[i];
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (d[i] > d[j]) {
swap(a[i], a[j]);
swap(b[i], b[j]);
swap(c[i], c[j]);
swap(d[i], d[j]);
}
}
}
for (int i = 0; i < n; i++) {
cout << a[i] << " " << b[i] << " " << c[i] << endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwppbnQgYVsxMDFdLCBiWzEwMV0sIGNbMTAxXSwgZFsxMDFdOwogCmludCBtYWluKCkgewoJaW50IG47CgljaW4gPj4gbjsKCWZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSB7CgkJY2luID4+IGFbaV0gPj4gYltpXSA+PiBjW2ldOwoJCWRbaV0gPSBhW2ldICogMzYwMCArIGJbaV0gKiA2MCArIGNbaV07Cgl9Cglmb3IgKGludCBpID0gMDsgaSA8IG47IGkrKykgewoJCWZvciAoaW50IGogPSBpICsgMTsgaiA8IG47IGorKykgewoJCQlpZiAoZFtpXSA+IGRbal0pIHsKCQkJCXN3YXAoYVtpXSwgYVtqXSk7CgkJCQlzd2FwKGJbaV0sIGJbal0pOwoJCQkJc3dhcChjW2ldLCBjW2pdKTsKCQkJCXN3YXAoZFtpXSwgZFtqXSk7CgkJCX0KCQl9Cgl9Cglmb3IgKGludCBpID0gMDsgaSA8IG47IGkrKykgewoJCWNvdXQgPDwgYVtpXSA8PCAiICIgPDwgYltpXSA8PCAiICIgPDwgY1tpXSA8PCBlbmRsOwoJfQoJcmV0dXJuIDA7Cn0=