#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
using namespace std;
typedef pair<int, int> Pii;

vector<int> watch[10];

int f(vector<int>& a) {
	return a[0] / 5 * 60 * 60 + a[1] * 60 + a[2];
}

string conv(int t) {
	string h = "00", m = "00", s = "00";
	int ss = t % 60, mm = t / 60 % 60, hh = t / 60 / 60;
	s[0] += ss / 10, s[1] += ss % 10;
	m[0] += mm / 10, m[1] += mm % 10;
	h[0] += hh / 10, h[1] += hh % 10;
	return h + ":" + m + ":" + s;
}

bool ok(vector<int>& a) {
	return a[0] % 5 == a[1] / 12;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	while(cin >> n, n) {
		for(int i = 0; i < n; i++) {
			vector<int> a(3);
			for(int j = 0; j < 3; j++) {
				cin >> a[j];
			}
			sort(a.begin(), a.end());
			watch[i] = a;
		}

		vector<Pii> v;
		for(int i = 0; i < n; i++) {
			vector<int> w = watch[i];
			do {
				for(int j = 0; j < 60; j++) {
					vector<int> a = w;
					for(int k = 0; k < 3; k++) {
						a[k] = (a[k] + j) % 60;
					}
					if(!ok(a)) continue;
					int t = f(a);
					v.push_back(Pii(t, i));
				}
			} while(next_permutation(w.begin(), w.end()));
		}
		sort(v.begin(), v.end());
		int m = v.size();

		int ans1 = 0, ans2 = 0;
		int anst = 1 << 28;
		for(int i = 0; i < m; i++) {
			int cnt = 1, t1 = v[i].first;
			vector<int> used(n);
			used[v[i].second] = 1;
			for(int j = 0; j < m; j++) {
				int id = v[(i + j + 1) % m].second, t2 = v[(i + j + 1) % m].first;
				if(!used[id]) {
					used[id] = 1;
					cnt++;
				}
				if(cnt == n) {
					int diff = (t2 + 43200 - t1) % 43200;
					if(anst > diff) {
						anst = diff;
						ans1 = t1;
						ans2 = t2;
					}
					break;
				}
			}
		}

		//cout << anst << endl;
		cout << conv(ans1) << " " << conv(ans2) << endl;
	}
}