#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

void enumCandidates(int h,int m,int s,vector<int> &cnd){
	rep(t,60){
		int hh=(h+t)%60,mm=(m+t)%60,ss=(s+t)%60;
		if(hh/5*5+mm/12==hh) cnd.push_back(hh/5*3600+mm*60+ss);
	}
}

int main(){
	for(int n;scanf("%d",&n),n;){
		vector<int> cnd[10];
		rep(i,n){
			int a[3]; rep(j,3) scanf("%d",a+j);
			sort(a,a+3);
			do{
				enumCandidates(a[0],a[1],a[2],cnd[i]);
			}while(next_permutation(a,a+3));
		}

		static int acc[10][43201];
		memset(acc,0,sizeof acc);
		rep(i,n) rep(j,cnd[i].size()) acc[i][cnd[i][j]+1]=1;
		rep(i,n) rep(t,43200) acc[i][t+1]+=acc[i][t];

		int ans=77777,t1_ans,t2_ans;
		rep(j,n) rep(i,j) {
			rep(k,cnd[i].size()) rep(l,cnd[j].size()) {
				int t1=min(cnd[i][k],cnd[j][l]);
				int t2=max(cnd[i][k],cnd[j][l]);

				bool ok=true;
				rep(p,n) if(acc[p][t2+1]-acc[p][t1]==0) ok=false;
				if(ok && (t2-t1<ans || t2-t1==ans && t1<t1_ans)){
					ans=t2-t1;
					t1_ans=t1;
					t2_ans=t2;
				}
			}
		}

		printf("%02d:%02d:%02d %02d:%02d:%02d\n",
			t1_ans/3600,t1_ans/60%60,t1_ans%60,
			t2_ans/3600,t2_ans/60%60,t2_ans%60);
	}

	return 0;
}