#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <array>
#include <cassert>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple

using namespace std;	

typedef long long ll;
typedef pair<int, int> P;
typedef unsigned long long ull;

void check(vector<int> v, vector<int> &cand){
	// h, m, s
	if (v[0] % 5 != v[1] / 12) return;
	cand.push_back(v[0] / 5 * 60 * 60 + v[1] * 60 + v[2]);
}

int main(){
	int n;
	while (cin >> n, n){
		vector<vector<int>> cand(n);
		rep(i, n){
			vector<int> v(3);
			rep(j, 3) cin >> v[j];
			rep(k, 60){
				sort(ALL(v));
				do{
					check(v, cand[i]);
				} while (next_permutation(ALL(v)));
				rep(j, 3) v[j] = (v[j] + 1) % 60;
			}
		}
		tuple<int, int, int> ans;
		ans = MT(1e9, 1e9, 1e9);
		rep(i, n) rep(j, cand[i].size()){
			int start = cand[i][j];
			int end = start;
			rep(k, n){
				if (i == k) continue;
				int tmp = 12 * 60 * 60;
				for (auto t : cand[k]){
					if (start > t) continue;
					tmp = min(tmp, t);
				}
				end = max(end, tmp);
			}
			if (end == 12 * 60 * 60) continue;
			ans = min(ans, MT(end - start, start, end));
		}
		int s, e, t;
		tie(t, s, e) = ans;
		printf("%02d:%02d:%02d %02d:%02d:%02d\n", s / 3600, s % 3600 / 60, s % 60, e / 3600, e % 3600 / 60, e % 60);
	}

	return 0;
}