#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cerr<<(#v)<<":";for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;
#define printVS(vs) cerr<<(#vs)<<":"<<endl;for(auto(s):(vs)){cerr<<(s)<< endl;}
#define printVV(vv) cerr<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;}
#define printP(p) cerr<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cerr<<(#vp)<<":"<<endl;for(auto(p):(vp)){cerr<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1e9;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

string padding(string s) {
    if (s.size() == 1) return "0"  + s;
    return s;
}

string conv(int t) {
    string ss = padding(to_string(t % 60)); t /= 60;
    string mm = padding(to_string(t % 60)); t /= 60;
    string hh = padding(to_string(t));
    return hh + ":" + mm + ":" + ss;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    const int T = 12*3600;

    int n;
    while (cin >> n, n) {
        vvi cnt(n, vi(T + 1));
        rep(id, n) {
            vi v(3);
            rep(j, 3) cin >> v[j];
            rep(f, 60) {
                sort(all(v));
                vi u = v;
                do {
                    if (u[0] % 5 == u[1] / 12) {
                        cnt[id][3600*(u[0]/5)+60*u[1]+u[2]]++;
                    }
                } while (next_permutation(all(u)));
                rep(j, 3) v[j] = (v[j] + 1) % 60;
            }
        }

        // rep(id, n) {
        //     cerr << "id = " << id << ":" << endl;
        //     rep(t, T) {
        //         if (cnt[id][t] > 0) cerr << conv(t) << " ";
        //     }
        //     cerr << endl;
        // }

        rep(id, n) rrep(t, T) cnt[id][t] += cnt[id][t+1];

        // rep(id, n) {
        //     cerr << "id = " << id << ":" << endl;
        //     rep(t, T) {
        //         if (cnt[id][t] - cnt[id][t+1] > 0) cerr << conv(t) << " ";
        //     }
        //     cerr << endl;
        // }

        auto existAll = [&](int l, int r) {
            rep(id, n) {
                if (cnt[id][l] - cnt[id][r] == 0) {
                    return false;
                }
            }
            return true;
        };

        // output(existAll(0, 11));
        // output(existAll(T-1, T-1));

        int mi = inf;
        int arg_l, arg_r;
        int r = 1;
        rep(l, T) {
            while (r < T && !existAll(l, r)) {
                r++;
            }
            if (r == T) break;
            if (mi > r - l) {
                // output(conv(l), conv(r - 1));
                mi = r - l;
                arg_l = l;
                arg_r = r;
            }
        }

        cout << conv(arg_l) << " " << conv(arg_r - 1) << endl;
    }

}

Measured memory_bytes: 4732