#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

bool isSame(int s, int t, int u, int sec, int min, int hour)
{
    vector<int> a(3), b(3);
    a[0] = s;
    a[1] = t;
    a[2] = u;
    b[0] = sec;
    b[1] = min;
    b[2] = hour;
    sort(a.begin(), a.end());

    for(int i=0; i<3; ++i){
        vector<int> c = b;
        for(int j=0; j<3; ++j){
            c[j] += a[i] - b[0] + 60;
            c[j] %= 60;
        }
        sort(c.begin(), c.end());
        if(a == c)
            return true;
    }
    return false;
}

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<int> s(n), t(n), u(n);
        for(int i=0; i<n; ++i)
            cin >> s[i] >> t[i] >> u[i];

        queue<pair<int, int> > q;
        vector<int> m(n, 0);
        int numZero = n;
        int ret = -1;
        int len = INT_MAX;
        for(int i=0; i<12*60*60; ++i){
            int sec = i % 60;
            int min = i / 60 % 60;
            int hour = i / (60 * 12);

            for(int j=0; j<n; ++j){
                if(isSame(s[j], t[j], u[j], sec, min, hour)){
                    if(m[j] == 0)
                        -- numZero;
                    ++ m[j];
                    q.push(make_pair(i, j));
                }
            }

            while(numZero == 0){
                if(i - q.front().first < len){
                    len = i - q.front().first;
                    ret = q.front().first;
                }
                if(m[q.front().second] == 1)
                    ++ numZero;
                -- m[q.front().second];
                q.pop();
            }
        }

        for(int i=0; i<2; ++i){
            int sec = (ret + i*len) % 60;
            int min = (ret + i*len) / 60 % 60;
            int hour = (ret + i*len) / (60 * 12);
            ostringstream oss;
            oss << setfill('0');
            oss << setw(2) << (hour/5) << ':' << setw(2) << min << ':' << setw(2) << sec;
            cout << oss.str();
            if(i == 0)
                cout << ' ';
        }
        cout << endl;
    }
}