#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(_,v.size())cout<<" "<<v[_];cout<<endl;
#define show2d(v) rep(_,v.size()){rep(__,v[_].size())cout<<" "<<v[_][__];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,int,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 1e18+10 : 1e9+10;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};//RDLU
//09062355704
int f(int a,int b,int c){
    int out=b*60+c;
    a-=b/12;
    if(a<0)a+=60;
    if(a%5)return -1;
    out+=a/5*3600;
    return out;
}
signed main(){
    int n;
    while(cin>>n,n){
        vvi in(n,vi(3));
        rep(i,n)rep(j,3)cin>>in[i][j];
        vi dp(43200,-inf);
        rep(i,n){
            vi t;
            rep(j,60){
                sort(all(in[i]));
                do{
                    int a=f(in[i][0],in[i][1],in[i][2]);
                    if(a+1)t.pb(a);
                }while(next_permutation(all(in[i])));
                rep(k,3)(in[i][k]+=1)%=60;
            }
          //show1d(t);
            vi ndp(43200,-inf);
            rep(j,43200)rep(k,t.size())if(i==0||dp[j]+inf){
                if(i==0){
                    ndp[t[k]]=t[k];
                    continue;
                }
                int mi=dp[j],ma=j;
                cmin(mi,t[k]);
                cmax(ma,t[k]);
                cmax(ndp[ma],mi);
            }
            dp=ndp;
        }
        int mi=inf,it;
        rep(i,43200)if(mi>i-dp[i]){
            mi=i-dp[i];
            it=i;
        }
//      cout<<it<<" "<<dp[it]<<endl;
        printf("%02d:%02d:%02d %02d:%02d:%02d\n",dp[it]/3600,dp[it]%3600/60,dp[it]%60,it/3600,it%3600/60,it%60);
    }
}

