/*
テヲツ慊?・ツ按敕」ツ?ォテ」ツ??0*60*60テ」ツつ津」ツつキテ」ツδ淌」ツδ・テ」ツδャテ」ツδシテ」ツδ暗ィツゥツヲテ」ツ?療」ツ?ヲテ」ツ?甘」ツ?湘」ツ?づ「ツ猟?

テ・ツ青?ヲツ卍づィツィツ暗」ツ?ォテ」ツ?、テ」ツ??」ツ?ヲテ」ツ??ヲツコツ?」ツ?淌」ツ?崚」ツつ凝ヲツ卍づゥツ鳴禿」ツつ津・ツ按療ヲツ個凖」ツ?凖」ツつ?
テ」ツδサテ・ツ青?ゥツ?敕」ツ?ョpermutationテ」ツつ津ヲツアツコテ」ツつ?」ツつ凝「ツ猟?
テ」ツδサテ」ツ?禿」ツ?ョpermutationテ」ツ?ォテ」ツ?、テ」ツ??」ツ?ヲテ」ツ??テ」ツ?堙」ツ?、テ」ツ?堙」ツつ嘉」ツ?療」ツ?ヲテ」ツ??0テ・ツ崢榲ィツサツ「テ」ツ?療」ツ?ヲテ」ツ??」ツ?湘」ツ?づ・ツ青?ァツ環カテヲツ?凝」ツ?ォテ」ツ?、テ」ツ??」ツ?ヲテ」ツ??ヲツ卍づゥツ鳴禿」ツつ津ヲツコツ?」ツ?淌」ツ?凖」ツ?凝ァツ「ツコティツェツ催」ツ?凖」ツつ凝」ツ?づ「ツ猟?

テ、ツクツ甘」ツ?ァテ・ツ按療ヲツ個凖」ツ?療」ツ?淌ヲツ卍づゥツ鳴禿」ツ?凝」ツつ嘉」ツ??テァツィツョテゥツ。ツ榲ゥツ?クテ」ツ?カテ」ツ?づ「ツ猟?
テ」ツ?禿」ツ?ョ2テァツィツョテゥツ。ツ榲」ツつ津ゥツ鳴凝・ツァツ凝ヲツ卍づ・ツ按サテ」ツ?ィテァツオツづ、ツコツ?ヲツ卍づ・ツ按サテ」ツ?ォテ」ツ?凖」ツつ凝」ツ?づ「ツ猟?

テヲツ卍づィツィツ暗」ツつ津ゥツ??ァツ閉ェテ」ツ?ォティツヲツ凝」ツ?ヲテ」ツ??ゥツ鳴凝・ツァツ凝ヲツ卍づ・ツ按サテ」ツ?ィテァツオツづ、ツコツ?ヲツ卍づ・ツ按サテ」ツ?ォテ・ツ?・テ」ツつ甘」ツ?敕」ツ??」ツ?凝ァツ「ツコティツェツ催」ツ?凖」ツつ凝」ツ??
*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstring>
using namespace std;

int toSec(const int &h, const int &m, const int &s){
  return s + m * 60 + h * 3600;
}

void showTime(int sec){
  int h = sec / 3600;
  int m = (sec % 3600) / 60;
  int s = sec % 60;
  printf("%02d:%02d:%02d", h, m, s);
}

void showTime(int h, int m, int s){
  printf("%02d:%02d:%02d", h, m, s);
}

//テ・ツ青?ゥツ?敕」ツ?ョテァツ環カテヲツ?凝」ツ?古、ツクツ偲」ツ?暗」ツつ凝」ツ?ィテ」ツ??ヲツ卍づゥツ鳴禿」ツつ津ィツソツ氾」ツ??
//[0][0][0]テ」ツつ?0:00:00テ」ツ?ィティツ?ε」ツ?暗」ツつ?
//-1テ」ツ?古ヲツ?シテァツエツ催」ツ?陛」ツつ古」ツ?ヲテ」ツ??」ツつ凝・ツ?エテ・ツ青暗」ツ??ゥツ?敕」ツ?ョテァツ環カテヲツ?凝」ツ?ィテ」ツ?療」ツ?ヲテ」ツ?づ」ツつ甘・ツセツ療」ツ?ェテ」ツ??
int times[60][60][60]; 

void mkTimes(){
  int hor = 0, posHor = 0;
  int min = 0;
  int sec = 0;

  memset(times, -1, sizeof(times));

  while(hor < 12){
    times[posHor][min][sec] = toSec(hor, min, sec);

    sec++;

    if(sec == 60){
      sec = 0;
      min++;
    }

    if(sec == 0 && min % 12 == 0){
      posHor++;
    }

    if(min == 60){
      min = 0;
      hor++;
    }
  }
}

void enumrate(vector<int> &v, vector<int> &allVec, int *perm){
  for(int i = 0; i < 60; i++){
    int tmp = times[perm[0]][perm[1]][perm[2]];
    perm[0] = (perm[0] + 1) % 60;
    perm[1] = (perm[1] + 1) % 60;
    perm[2] = (perm[2] + 1) % 60;

    if(tmp == -1) continue;
    v.push_back(tmp);
    allVec.push_back(tmp);
  }
}

bool check(int start, int end, const vector<int> &v){
  for(int i = 0; i < v.size(); i++){
    if(start <= v[i] && v[i] <= end) return true;
  }
  return false;
}

int main(){
  mkTimes();

  while(1){
    int n;
    cin >> n;
    if(n == 0) break;

    vector<int> t[12];
    vector<int> allVec;

    for(int i = 0; i < n; i++){
      int perm[3];
      for(int j = 0; j < 3; j++){
        cin >> perm[j];
      }
      sort(perm, perm + 3);
      do{
        enumrate(t[i], allVec, perm);
      }while(next_permutation(perm, perm + 3));
    }

    int ansStart = -1, ansEnd = 999999999;

    for(int i = 0; i < allVec.size(); i++){
      for(int j = i + 1; j < allVec.size(); j++){
        int start = allVec[i];
        int end = allVec[j];
        if(start > end) swap(start, end);

        bool flg = true;

        for(int k = 0; k < n; k++){
          if(!check(start, end, t[k])){
            flg = false;
            break;
          }
        }

        if(!flg) continue;

        if(ansEnd - ansStart > end - start ||
           ansEnd - ansStart == end - start && ansStart > start){
          ansStart = start;
          ansEnd = end;
        }
      }
    }

    showTime(ansStart);
    cout << " ";
    showTime(ansEnd);
    cout << endl;
  }
}

Measured memory_bytes: 2104