#include <bits/stdc++.h>

using namespace std;

const int INF = 1 << 30;

int main()
{
  int N, S[10][3];

  while(scanf("%d", &N), N) {

    for(int i = 0; i < N; i++) {
      for(int j = 0; j < 3; j++) scanf("%d", &S[i][j]);
      sort(S[i], S[i] + 3);
    }

    vector< int > g[10], vs;

    for(int i = 0; i < 12; i++) {
      for(int j = 0; j < 60; j++) {
        for(int k = 0; k < 60; k++) {
          int a = k, b = j, c = (i * 60 + j) / 12;
          for(int l = 0; l < N; l++) {
            bool flag = false;
            do flag |= (S[l][0] - a + 60) % 60 == (S[l][1] - b + 60) % 60 && (S[l][0] - a + 60) % 60 == (S[l][2] - c + 60) % 60;
            while(next_permutation(begin(S[l]), end(S[l])));
            if(flag) g[l].push_back(i * 3600 + j * 60 + k);
          }
        }
      }
    }

    for(int i = 0; i < N; i++) {
      copy(begin(g[i]), end(g[i]), back_inserter(vs));
    }
    sort(begin(vs), end(vs));
    vs.erase(unique(begin(vs), end(vs)), end(vs));

    int ret = INF, now;
    for(int &t : vs) {
      int res = 0, i = 0;
      while(i < N) {
        auto p = lower_bound(begin(g[i]), end(g[i]), t);
        if(p == end(g[i])) break;
        res = max(res, *p - t);
        i++;
      }

      if(i == N && ret > res) ret = res, now = t;
    }
    printf("%02d:%02d:%02d ", now / 3600, now / 60 % 60, now % 60);
    now += ret;
    printf("%02d:%02d:%02d\n", now / 3600, now / 60 % 60, now % 60);
  }
}