#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template<typename T1, typename T2>
void chmax(T1 &a, const T2 &b) {
  if (a < b) a = b;
}
template<typename T1, typename T2>
void chmin(T1 &a, const T2 &b) {
  if (a > b) a = b;
}
template<typename T>
void printv(const vector<T> &s) {
  for (int i = 0; i < (int) (s.size()); ++i) {
    cout << s[i];
    if (i != (int) (s.size()) - 1) cout << " ";
  }
  cout << "\n";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
struct Time {
  int s, t, u;
  ll hash;
  Time(int s, int t, int u) : s(s), t(t), u(u) {}
};
bool operator<(const Time &t1, const Time &t2) {
  return t1.hash < t2.hash;
}
void add_elm(int i, int s, int t, int u, vector<set<Time>> &v) {
  for(int j=0;j<60;++j) {
    if ((s+j)%5 == (t+j)%60/12) {
      auto now = Time((s + j) / 5 % 12, (t + j) % 60, (u + j) % 60);
      now.hash = 60 * 60 * now.s + 60 * now.t + now.u;
      v[i].insert(now);
    }
  }
}
bool solve() {
  int n;
  cin >> n;
  if(n == 0) return false;
  vector<set<Time>> v(n);
  for(int i=0;i<n;++i) {
    int s, t, u;
    cin >> s >> t >> u;
    add_elm(i, s, t, u, v);
    add_elm(i, s, u, t, v);
    add_elm(i, t, s, u, v);
    add_elm(i, t, u, s, v);
    add_elm(i, u, s, t, v);
    add_elm(i, u, t, s, v);
  }
  vector<ll> a(n);
  vector<set<Time>::iterator> pos(n);
  for(int i=0;i<n;++i) {
    pos[i] = v[i].begin();
  }
  ll l = LINF, r = 0;
  int argmi = -1;
  for(int i=0;i<n;++i) {
    a[i] = pos[i]->hash;
    pos[i]++;
    if (l > a[i]) {
      l = a[i];
      argmi = i;
    }
    chmax(r, a[i]);
  }
  ll ans = r - l;
  ll ansl = l, ansr = r;
  while (1) {
    if (pos[argmi] == v[argmi].end()) break;
    a[argmi] = pos[argmi]->hash;
    pos[argmi]++;
    ll l = LINF, r = 0;
    for(int i=0;i<n;++i) {
      if (l > a[i]) {
        l = a[i];
        argmi = i;
      }
      chmax(r, a[i]);
    }
    if (ans > r - l) {
      ans = r - l;
      ansl = l;
      ansr = r;
    } else if(ans == r - l && ansl > l) {
      ansl = l;
      ansr = r;
    }
  }
  printf("%02lld:%02lld:%02lld ", ansl / 3600 % 12, ansl / 60 % 60, ansl % 60);
  printf("%02lld:%02lld:%02lld\n", ansr / 3600 % 12, ansr / 60 % 60, ansr % 60);
  return true;
}
int main() {
  while(1) {
    if(!solve()) break;
  }
}

