#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;
long long int powint(long long int a, long long int b) {
	assert(b >= 0);
	if (b == 0)return 1;
	if (b == 1)return a;
	long long int ans = 1;
	long long int aa = powint(a, b / 2);
	ans *= aa*aa;
	if (b % 2)ans *= a;
	return ans;
}
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,1,0,-1 };
//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"

int change_color(vector<vector<int>>&fi, const int to_co) {
	queue<pair<int, int>>que;
	const int from_co = fi[1][1];
	que.push(make_pair(1, 1));
	fi[1][1] = -1;
	while (!que.empty()) {
		const auto p(que.front());
		que.pop();
		for (int way = 0; way < 4; ++way) {
			const int nextx = p.first + dx[way];
			const int nexty = p.second + dy[way];
			if (fi[nexty][nextx] == from_co) {
				fi[nexty][nextx] = -1;
				que.push(make_pair(nextx, nexty));
			}
		}
	}
	int num = 0;
	for (auto& l : fi) {
		for (auto& e : l) {
			if (e == -1) {
				num++;
				e = to_co;
			}
		}
	}
	return num;
}

int solve(const vector<vector<int>>&ori_fi, const int rest,const int fin) {
	if (!rest) {
		vector<vector<int>>n_fi(ori_fi);
		return change_color(n_fi, -1);
	}
	int amax = 0;
	for (int nc = 1; nc <= 6; ++nc) {
		if (rest == 1 && nc != fin)continue;
		vector<vector<int>>n_fi(ori_fi);
		change_color(n_fi, nc);
		amax = max(amax, solve(n_fi, rest - 1,fin));
	}
	return amax;
}

vector<int>normal(vector<int>nums) {
	sort(nums.begin(), nums.end());
	vector<vector<int>>numss;
	numss.push_back(nums);
	rotate(nums.begin(), nums.begin() + 1, nums.end());
	numss.push_back(nums);
	rotate(nums.begin(), nums.begin() + 1, nums.end());
	numss.push_back(nums);
	auto it = min_element(numss.begin(), numss.end(), [](const vector<int>&l,const vector<int>&r) {
		return ((60 + l[1] - l[0]) % 60)==((60 + r[1] - r[0]) % 60)? ((60 + l[2] - l[1]) % 60)<((60 + r[2] - r[1]) % 60):((60 + l[1] - l[0]) % 60)<((60+r[1]-r[0])%60);
	});
	vector<int>clock(*it);
	transform(clock.begin(), clock.end(), clock.begin(), [=](const int n) {return (60 + n - clock[0]) % 60; });
	return clock;
}
vector<int> getclock(int time) {
	int sec = time % 60;
	int min = (time / 60) % 60;
	int hou = (time / 720) % 60;
	vector<int>nums{ sec,min,hou };
	return normal(nums);
}


string gettime(const int time) {
	int sec = time % 60;
	int min = (time / 60) % 60;
	int hou = (time / 3600) % 60;
	string st;
	vector<int>nums{ hou,min,sec };
	for (int i = 0; i < 3;++i)
	{
		string s(to_string(nums[i]));
		if (s.size() == 1)s = '0' + s;
		st += s;
		if (i != 2)st += ':';
	}
	return st;

}
int main() {
	vector<vector<int>>times;
	for (int t = 0; t < 43200; ++t) {
		times.emplace_back(getclock(t));
	}
	while (1) {
		int N; cin >> N;
		if (!N)break;
		vector<vector<int>>clocks;
		vector<vector<int>>oks(N,vector<int>(43200));
		for (int i = 0; i < N; ++i) {
			vector<int>nums(3);
			for (int j = 0; j < 3; ++j) {
				cin >> nums[j];
			}
			nums = normal(nums);
			clocks.emplace_back(nums);
			for (int t = 0; t < 43200; ++t) {
				if (nums == times[t]) {
					oks[i][t] = true;
				}
			}
		}
		int ans = 1e5;
		int from, to;
		int l = 0, r =0;
		vector<int>nowoks(N);
		for (int i = 0; i < N; ++i) {
			if (oks[i][l])nowoks[i]++;
		}
		while (l<43200) {
			if (all_of(nowoks.begin(), nowoks.end(), [](const int ok) {return ok; })) {
				if (ans > r - l) {
					from = l;
					to = r;
					ans = r - l;
				}
				for (int i = 0; i < N; ++i) {
					if (oks[i][l])nowoks[i]--;
				}
				l++;
			}
			else {
				r++;
				for (int i = 0; i < N; ++i) {
					if (oks[i][r % 43200])nowoks[i]++;
				}
			}
		}
		string start(gettime(from));
		string goal(gettime(to));
		cout << start << " " << goal << endl;
	}
	return 0;
}

Measured memory_bytes: 7264