#include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#include<sstream>
#include<fstream>
#include<algorithm>
using namespace std;
string t[52];
string update(string s)
{
int h1 = s[0] - '0';
int h2 = s[1] - '0';
int m1 = s[3] - '0';
int m2 = s[4] - '0';
//update
m2++;
if (m2 == 10) {
m2 = 0;
m1++;
if (m1 == 6) {
m1 = 0;
h2++;
if (h2 == 10) {
h2 = 0;
h1++;
} else if (h2 == 4 && h1 == 2) {
h2 = 0;
h1 = 0;
}
}
}
string r = "";
r += h1 + '0';
r += h2 + '0';
r += ":";
r += m1 + '0';
r += m2 + '0';
return r;
}
int valid(int h1, int h2, int m1, int m2)
{
if (h1 > 2)
return 0;
if (h2 > 9)
return 0;
if (m1 > 5)
return 0;
if (m2 > 9)
return 0;
if (h1 == 2 && h2 > 3)
return 0;
return 1;
}
int same(int h1, int h2, int m1, int m2, string cur)
{
if (cur[0] == '1') {
if (h1 != 0 and h1 != 1)
return 0;
} else if (cur[0] == '2') {
if (h1 != 2)
return 0;
} else if (cur[0] == '0') {
if (h1 != 0)
return 0;
} else if (cur[0] == '7') {
if (h1 != 0)
return 0;
} else
return 0;
if (cur[1] == '1') {
if (h2 != 0 and h2 != 1 and h2 != 3 and h2 != 4 and h2 != 7 and h2 != 8 and h2 != 9)
return 0;
} else if (cur[1] == '2') {
if (h2 != 2 and h2 != 8)
return 0;
} else if (cur[1] == '0') {
if (h2 != 0 and h2 != 8)
return 0;
} else if (cur[1] == '3') {
if (h2 != 8 and h2 != 9 and h2 != 3)
return 0;
} else if (cur[1] == '4') {
if (h2 != 4 and h2 != 8 and h2 != 9)
return 0;
} else if (cur[1] == '5') {
if (h2 != 5 and h2 != 6 and h2 != 8 and h2 != 9)
return 0;
} else if (cur[1] == '6') {
if (h2 != 6 and h2 != 8)
return 0;
} else if (cur[1] == '7') {
if (h2 != 0 and h2 != 7 and h2 != 3 and h2 != 8 and h2 != 9)
return 0;
} else if (cur[1] == '8') {
if (h2 != 8)
return 0;
} else if (cur[1] == '9') {
if (h2 != 9 and h2 != 8)
return 0;
} else
return 0;
if (cur[4] == '1') {
if (m2 != 0 and m2 != 1 and m2 != 3 and m2 != 4 and m2 != 7 and m2 != 8 and m2 != 9)
return 0;
} else if (cur[4] == '2') {
if (m2 != 2 and m2 != 8)
return 0;
} else if (cur[4] == '0') {
if (m2 != 0 and m2 != 8)
return 0;
} else if (cur[4] == '3') {
if (m2 != 8 and m2 != 9 and h2 != 3)
return 0;
} else if (cur[4] == '4') {
if (m2 != 4 and m2 != 8 and m2 != 9)
return 0;
} else if (cur[4] == '5') {
if (m2 != 5 and m2 != 6 and m2 != 8 and m2 != 9)
return 0;
} else if (cur[4] == '6') {
if (m2 != 6 and m2 != 8)
return 0;
} else if (cur[4] == '7') {
if (m2 != 0 and m2 != 7 and m2 != 3 and m2 != 8 and m2 != 9)
return 0;
} else if (cur[4] == '8') {
if (m2 != 8)
return 0;
} else if (cur[4] == '9') {
if (m2 != 9 and h2 != 8)
return 0;
} else
return 0;
if (cur[3] == '1') {
if (m1 != 0 and m1 != 1 and m1 != 3 and m1 != 4)
return 0;
} else if (cur[3] == '2') {
if (m1 != 2)
return 0;
} else if (cur[3] == '0') {
if (m1 != 0)
return 0;
} else if (cur[3] == '3') {
if (m1 != 3)
return 0;
} else if (cur[3] == '4') {
if (m1 != 4)
return 0;
} else if (cur[3] == '5') {
if (m1 != 5)
return 0;
} else if (cur[3] == '7') {
if (m1 != 9 and m1 != 3)
return 0;
} else
return 0;
return 1;
}
int N;
int dfs(int h1, int h2, int m1, int m2, int i)
{
if (i == N)
return 1;
if (!valid(h1, h2, m1, m2))
return 0;
if (!same(h1, h2, m1, m2, t[i]))
return 0;
//update
m2++;
if (m2 == 10) {
m2 = 0;
m1++;
if (m1 == 6) {
m1 = 0;
h2++;
if (h2 == 10) {
h2 = 0;
h1++;
} else if (h2 == 4 && h1 == 2) {
h2 = 0;
h1 = 0;
}
}
}
return dfs(h1, h2, m1, m2, i + 1);
}
int main()
{
string s;
while (getline(cin, s)) {
istringstream in(s);
in >> N;
for (int i = 0; i < N; i++) {
in >> t[i];
}
vector < int >h1, h2, m1, m2;
h1.clear();
h2.clear();
m1.clear();
m2.clear();
if (t[0][0] == '1') {
h1.push_back(0);
h1.push_back(1);
}
if (t[0][0] == '2')
h1.push_back(2);
if (t[0][0] == '0')
h1.push_back(0);
if (t[0][0] == '7')
h1.push_back(0);
// h2
if (t[0][1] == '1') {
h2.push_back(0);
h2.push_back(1);
h2.push_back(3);
h2.push_back(4);
h2.push_back(7);
h2.push_back(8);
h2.push_back(9);
}
if (t[0][1] == '2') {
h2.push_back(2);
h2.push_back(8);
}
if (t[0][1] == '0') {
h2.push_back(0);
h2.push_back(8);
}
if (t[0][1] == '3') {
h2.push_back(3);
h2.push_back(8);
h2.push_back(9);
}
if (t[0][1] == '4') {
h2.push_back(4);
h2.push_back(8);
h2.push_back(9);
}
if (t[0][1] == '5') {
h2.push_back(5);
h2.push_back(6);
h2.push_back(8);
h2.push_back(9);
}
if (t[0][1] == '6') {
h2.push_back(6);
h2.push_back(8);
}
if (t[0][1] == '7') {
h2.push_back(0);
h2.push_back(7);
h2.push_back(3);
h2.push_back(8);
h2.push_back(9);
}
if (t[0][1] == '8') {
h2.push_back(8);
}
if (t[0][1] == '9') {
h2.push_back(9);
h2.push_back(8);
}
// m2
if (t[0][4] == '1') {
m2.push_back(0);
m2.push_back(1);
m2.push_back(3);
m2.push_back(4);
m2.push_back(7);
m2.push_back(8);
m2.push_back(9);
}
if (t[0][4] == '2') {
m2.push_back(2);
m2.push_back(8);
}
if (t[0][4] == '0') {
m2.push_back(0);
m2.push_back(8);
}
if (t[0][4] == '3') {
m2.push_back(3);
m2.push_back(8);
m2.push_back(9);
}
if (t[0][4] == '4') {
m2.push_back(4);
m2.push_back(8);
m2.push_back(9);
}
if (t[0][4] == '5') {
m2.push_back(5);
m2.push_back(6);
m2.push_back(8);
m2.push_back(9);
}
if (t[0][4] == '6') {
m2.push_back(6);
m2.push_back(8);
}
if (t[0][4] == '7') {
m2.push_back(0);
m2.push_back(7);
m2.push_back(3);
m2.push_back(8);
m2.push_back(9);
}
if (t[0][4] == '8') {
m2.push_back(8);
}
if (t[0][4] == '9') {
m2.push_back(9);
m2.push_back(8);
}
// m1
if (t[0][3] == '1') {
m1.push_back(0);
m1.push_back(1);
m1.push_back(3);
m1.push_back(4);
}
if (t[0][3] == '2') {
m1.push_back(2);
}
if (t[0][3] == '0') {
m1.push_back(0);
}
if (t[0][3] == '3') {
m1.push_back(3);
}
if (t[0][3] == '4') {
m1.push_back(4);
}
if (t[0][3] == '5') {
m1.push_back(5);
}
if (t[0][3] == '7') {
m1.push_back(0);
m1.push_back(3);
}
vector < string > ret;
ret.clear();
for (int i = 0; i < h1.size(); i++)
for (int j = 0; j < h2.size(); j++)
for (int k = 0; k < m1.size(); k++)
for (int z = 0; z < m2.size(); z++) {
int c = 1;
c &= dfs(h1[i], h2[j], m1[k], m2[z], 0);
if (c) {
string r = "";
r += h1[i] + '0';
r += h2[j] + '0';
r += ":";
r += m1[k] + '0';
r += m2[z] + '0';
ret.push_back(r);
}
}
if (ret.size() == 0)
cout << "none" << endl;
else {
sort(ret.begin(), ret.end());
vector < string > is;
for (int i = 0; i < ret.size(); i++) {
vector < string > cc;
cc.clear();
string ccur = ret[i];
for (int j = 0; j < N; j++) {
cc.push_back(ccur);
ccur = update(ccur);
}
int count = 0;
for (int j = 0; j < 5; j++) {
if (j == 2)
continue;
int R[7], a[7], b[7];
memset(R, 0, sizeof(R));
for (int k = 0; k < cc.size(); k++) {
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
if (cc[k][j] == '0') {
b[0] = 1;
b[1] = 1;
b[2] = 1;
b[3] = 1;
b[4] = 1;
b[5] = 1;
}
if (cc[k][j] == '1') {
b[1] = 1;
b[2] = 1;
}
if (cc[k][j] == '2') {
b[0] = 1;
b[1] = 1;
b[6] = 1;
b[3] = 1;
b[4] = 1;
}
if (cc[k][j] == '3') {
b[0] = 1;
b[1] = 1;
b[6] = 1;
b[3] = 1;
b[2] = 1;
}
if (cc[k][j] == '4') {
b[1] = 1;
b[2] = 1;
b[6] = 1;
b[5] = 1;
}
if (cc[k][j] == '5') {
b[0] = 1;
b[5] = 1;
b[6] = 1;
b[2] = 1;
b[3] = 1;
}
if (cc[k][j] == '6') {
b[0] = 1;
b[5] = 1;
b[6] = 1;
b[2] = 1;
b[3] = 1;
b[4] = 1;
}
if (cc[k][j] == '7') {
b[0] = 1;
b[1] = 1;
b[2] = 1;
}
if (cc[k][j] == '8') {
b[0] = 1;
b[1] = 1;
b[2] = 1;
b[3] = 1;
b[4] = 1;
b[5] = 1;
b[6] = 1;
}
if (cc[k][j] == '9') {
b[0] = 1;
b[1] = 1;
b[2] = 1;
b[3] = 1;
b[5] = 1;
b[6] = 1;
}
//t
if (t[k][j] == '0') {
a[0] = 1;
a[1] = 1;
a[2] = 1;
a[3] = 1;
a[4] = 1;
a[5] = 1;
}
if (t[k][j] == '1') {
a[1] = 1;
a[2] = 1;
}
if (t[k][j] == '2') {
a[0] = 1;
a[1] = 1;
a[6] = 1;
a[3] = 1;
a[4] = 1;
}
if (t[k][j] == '3') {
a[0] = 1;
a[1] = 1;
a[6] = 1;
a[3] = 1;
a[2] = 1;
}
if (t[k][j] == '4') {
a[1] = 1;
a[2] = 1;
a[6] = 1;
a[5] = 1;
}
if (t[k][j] == '5') {
a[0] = 1;
a[5] = 1;
a[6] = 1;
a[2] = 1;
a[3] = 1;
}
if (t[k][j] == '6') {
a[0] = 1;
a[5] = 1;
a[6] = 1;
a[2] = 1;
a[3] = 1;
a[4] = 1;
}
if (t[k][j] == '7') {
a[0] = 1;
a[1] = 1;
a[2] = 1;
}
if (t[k][j] == '8') {
a[0] = 1;
a[1] = 1;
a[2] = 1;
a[3] = 1;
a[4] = 1;
a[5] = 1;
a[6] = 1;
}
if (t[k][j] == '9') {
a[0] = 1;
a[1] = 1;
a[2] = 1;
a[3] = 1;
a[5] = 1;
a[6] = 1;
}
for (int z = 0; z < 7; z++)
if (!R[z])
R[z] = a[z] ^ b[z];
}
int ok = 1;
for (int k = 0; k < N; k++) {
memset(a, 0, sizeof(a));
//t
if (t[k][j] == '0') {
a[0] = 1;
a[1] = 1;
a[2] = 1;
a[3] = 1;
a[4] = 1;
a[5] = 1;
}
if (t[k][j] == '1') {
a[1] = 1;
a[2] = 1;
}
if (t[k][j] == '2') {
a[0] = 1;
a[1] = 1;
a[6] = 1;
a[3] = 1;
a[4] = 1;
}
if (t[k][j] == '3') {
a[0] = 1;
a[1] = 1;
a[6] = 1;
a[3] = 1;
a[2] = 1;
}
if (t[k][j] == '4') {
a[1] = 1;
a[2] = 1;
a[6] = 1;
a[5] = 1;
}
if (t[k][j] == '5') {
a[0] = 1;
a[5] = 1;
a[6] = 1;
a[2] = 1;
a[3] = 1;
}
if (t[k][j] == '6') {
a[0] = 1;
a[5] = 1;
a[6] = 1;
a[2] = 1;
a[3] = 1;
a[4] = 1;
}
if (t[k][j] == '7') {
a[0] = 1;
a[1] = 1;
a[2] = 1;
}
if (t[k][j] == '8') {
a[0] = 1;
a[1] = 1;
a[2] = 1;
a[3] = 1;
a[4] = 1;
a[5] = 1;
a[6] = 1;
}
if (t[k][j] == '9') {
a[0] = 1;
a[1] = 1;
a[2] = 1;
a[3] = 1;
a[5] = 1;
a[6] = 1;
}
for (int z = 0; z < 7; z++)
if (R[z] && a[z])
ok = 0;
}
if (ok)
count++;
}
if (count == 4)
is.push_back(ret[i]);
}
if (is.size() == 0)
cout << "none" << endl;
else {
for (int i = 0; i < is.size() - 1; i++)
cout << is[i] << " ";
cout << is[is.size() - 1] << endl;
}
is.clear();
}
}
return 0;
}