#include <bits/stdc++.h>

using namespace std;

namespace {

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }

    int N;
    vector<int> S, T, U;
    bool input() {
        cin >> N;
        if (N == 0) return false;
        S.clear(); T.clear(); U.clear();
        for (int i = 0; i < N; i++) {
            int s, t, u; cin >> s >> t >> u;
            S.push_back(s);
            T.push_back(t);
            U.push_back(u);
        }
        return true;
    }

    struct H {
        int h, m, s;
        int index;
        H(int h, int m, int s) : h(h), m(m), s(s) {}
        H(int t) {
            h = t / 3600; t %= 3600;
            m = t / 60;   t %= 60;
            s = t;
        }
        bool operator<(const H& x) const {
            if (h == x.h) {
                if (m == x.m) return s < x.s;
                return m < x.m;
            } else {
                return h < x.h;
            }
        }
        int time() const {
            return h * 3600 + m * 60 + s;
        }
    };
    ostream& operator<<(ostream& os, const H& h) {
        char buf[256];
        sprintf(buf, "%02d:%02d:%02d", h.h, h.m, h.s);
        return os << buf;
    }
    int operator-(const H& a, const H& b) {
        return a.time() - b.time();
    }

    bool all(const vector<int>& count) {
        for (int i = 0; i < count.size(); i++) {
            if (count[i] == 0) return false;
        }
        return true;
    }

    void solve() {
        set<H> C;
        for (int t = 0; t < 24 * 60 * 60; t++) {
            C.insert(H(t));
        }
        vector<H> V;
        for (int i = 0; i < N; i++) {
            for (int k = 0; k < 60; k++) {
                vector<int> xs;
                xs.push_back( (S[i] + k) % 60 );
                xs.push_back( (T[i] + k) % 60 );
                xs.push_back( (U[i] + k) % 60 );
                sort(xs.begin(), xs.end());
                do {
                    int h = xs[0] / 5;
                    int m = xs[1];
                    int s = xs[2];
                    int r = xs[0] % 5;
                    if (r * 12 <= m && m < (r + 1) * 12) {
                        H t(h, m, s);
                        t.index = i;
                        if (C.count(t)) {
                            V.push_back(t);
                        }
                    }
                } while (next_permutation(xs.begin(), xs.end()));
            }
            sort(V.begin(), V.end());
        }
        int s = 0, t = -1;
        vector<int> count(N, 0);
        int ans = 1<<28;
        int index = -1;
        while (true) {
            //cout << s << " " << t << endl;
            if (all(count)) {
                if (ans > V[t] - V[s]) {
                    ans = V[t] - V[s];
                    index = s;
                }
                count[V[s].index]--;
                s++;
            } else {
                t++;
                if (t == V.size()) break;
                count[V[t].index]++;
            }
        }
        cout << V[index] << " " << H(ans + V[index].time()) << endl;
    }
}

int main() {
    while (input()) solve();
    return 0;
}

Measured memory_bytes: 6688