#include #include #include #include #include #include #define REP(i, to) for(int i = 0 ; i < to ; ++i) using namespace std; const char Digit[11][5][3] = { {{'?','-','?'}, {'|','?','|'}, {'?','.','?'}, {'|','?','|'}, {'?','-','?'}}, //0 {{'?','.','?'}, {'.','?','|'}, {'?','.','?'}, {'.','?','|'}, {'?','.','?'}}, //1 {{'?','-','?'}, {'.','?','|'}, {'?','-','?'}, {'|','?','.'}, {'?','-','?'}}, //2 {{'?','-','?'}, {'.','?','|'}, {'?','-','?'}, {'.','?','|'}, {'?','-','?'}}, //3 {{'?','.','?'}, {'|','?','|'}, {'?','-','?'}, {'.','?','|'}, {'?','.','?'}}, //4 {{'?','-','?'}, {'|','?','.'}, {'?','-','?'}, {'.','?','|'}, {'?','-','?'}}, //5 {{'?','-','?'}, {'|','?','.'}, {'?','-','?'}, {'|','?','|'}, {'?','-','?'}}, //6 {{'?','-','?'}, {'.','?','|'}, {'?','.','?'}, {'.','?','|'}, {'?','.','?'}}, //7 {{'?','-','?'}, {'|','?','|'}, {'?','-','?'}, {'|','?','|'}, {'?','-','?'}}, //8 {{'?','-','?'}, {'|','?','|'}, {'?','-','?'}, {'.','?','|'}, {'?','-','?'}}, //9 {{'?','.','?'}, {'.','?','.'}, {'?','.','?'}, {'.','?','.'}, {'?','.','?'}}, //0 }; class Clock { public: char d[5][18]; set pH; set pM; set Canbe; int next_h; int next_m; void Read(); }; void Clock::Read() { getchar(); REP(i, 5) { REP(j, 18) {d[i][j] = getchar();} getchar();} //cout << "Read: " << endl; //REP(i, 5) { REP(j, 18) cout << d[i][j]; cout << "#" << endl;} //cout << "EndRead: " << endl; int pad[4] = {0, 4, 11, 15}; vector pos[4]; REP(cipher, 4){ REP(i, 11) { bool can = true; REP(a, 5) REP(b, 3) { char di=Digit[i][a][b]; char in=d[a][b+pad[cipher]]; if(di == '?' || in == '?' || di==' ' || in==' ') continue; if(di != in) { can = false; //cout << "C:" << cipher << " i:" << i << " a:" << a << " b:" << b << " di: " << di << " in: " << in << endl; //break; } } if(can) { if(cipher == 0 || i != 10) pos[cipher].push_back(i); //cout << "PUSH: " << i << endl; } } } REP(a, (int)pos[0].size()) REP(b, (int)pos[1].size()) if((pos[0][a] % 10)*10 + pos[1][b] < 24) pH.insert(pos[0][a]*10 + pos[1][b]); REP(a, (int)pos[2].size()) REP(b, (int)pos[3].size()) if((pos[2][a] % 10)*10 + pos[3][b] < 60) pM.insert(pos[2][a]*10 + pos[3][b]); REP(i, 24) if(pH.find(i) != pH.end()) REP(j, 60) if(pM.find(j) != pM.end()) { this->Canbe.insert(i * 60 + j); //cout << i << ":" << j << endl; } /* REP(a, (int)pos[0].size()) REP(b, (int)pos[1].size()) if((pos[0][a] % 10)*10 + pos[1][b] < 24) REP(c, (int)pos[2].size()) REP(d, (int)pos[3].size()) if((pos[2][c] % 10)*10 + pos[3][d] < 60) this->Canbe.insert(i * 60 + j) */ } int main() { while(true) { int N; scanf("%d", &N); if(N == 0) break; Clock C[N]; REP(i, N) { C[i].Read(); if(i != N-1){ scanf("%d%d", &C[i].next_h, &C[i].next_m); } } //down and up with set intersection REP(i, 2*N - 2){ int a, b; int oper=-1; int next_t_i; if(i < N-1) {b=i; a=i+1;oper=-1; next_t_i = b;} else {b=2*N-2-i; a=b-1; oper=1; next_t_i = a;} set::iterator iter = C[a].Canbe.begin(); while(iter != C[a].Canbe.end()){ bool ok = false; //cout << "T to find " << endl; for(int t = C[next_t_i].next_h ; t <= C[next_t_i].next_m ; t++){ int t_to_find = (1440 + oper*t + *iter) % 1440; //cout << t_to_find << endl; if(C[b].Canbe.find(t_to_find) != C[b].Canbe.end()) { ok = true; break; } } set::iterator jter = iter; ++iter; if(!ok){ C[a].Canbe.erase(jter); } } //Important debug stuff /* cout << "Intersection (" << a << ", " << b << ")" << endl; for(iter = C[a].Canbe.begin(); iter != C[a].Canbe.end() ; iter++) { int minutes = (*iter % 60); cout << (*iter / 60) << ":" << ((minutes < 10)?"0":"") << minutes << " "; }*/ } REP(i, N){ if(C[i].Canbe.size() == 1) { set::iterator iter = C[i].Canbe.begin(); int minutes = (*iter % 60); cout << (*iter / 60) << ":" << ((minutes < 10)?"0":"") << minutes << endl; } else{ cout << "ambiguous, " << C[i].Canbe.size() << " possibilities" << endl; } } cout << endl; } return 0; }