
#include <iostream>
 
#include <algorithm>
 
using namespace std;
int main() {
  int hours[100];
  int mins[100];
  int secs[100];
  int all_time[100];
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> hours[i] >> mins[i] >> secs[i];
    all_time[i] = hours[i] * 3600 + mins[i] * 60 + secs[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (all_time[i] > all_time[j]) {
        swap(hours[i], hours[j]); swap(mins[i], mins[j]);
        swap(secs[i], secs[j]); swap(all_time[i], all_time[j]);
      }
    }
  }
  for (int i = 0; i < n; i++) cout << hours[i] << " " << mins[i] << " " << secs[i] << endl;
}