#include #include using namespace atcoder; using namespace std; using ll = long long; using vll = vector; using vvll = vector; using vvvll = vector; #define all(A) A.begin(),A.end() #define rep(i, n) for (ll i = 0; i < (ll) (n); i++) bool chmax(ll& p, ll q) { if (p < q) { p = q; return 1; } else { return 0; } } bool chmin(ll& p, ll q) { if (p > q) { p = q; return 1; } else { return 0; } } ll PM(ll P, ll Q) { if (Q == 0)return P * 10; ll k = 1; ll V = Q; while (V > 0) { V /= 10; k *= 10; } return P * k + Q; } int main() { ll N; cin >> N; if (N > 26) { cout << "Impossible" << endl; return 0; } vector S(N); rep(i, N)cin >> S[i]; two_sat ts(N); rep(i, N)rep(j, i) { if (S[i].substr(0, 1) == S[j].substr(0, 1)) { ts.add_clause(i, 1, j, 1); } if (S[i].substr(0, 1) == S[j].substr(2, 1)) { ts.add_clause(i, 1, j, 0); } if (S[i].substr(2, 1) == S[j].substr(0, 1)) { ts.add_clause(i, 0, j, 1); } if (S[i].substr(2, 1) == S[j].substr(2, 1)) { ts.add_clause(i,0, j, 0); } if (S[i].substr(1, 2) == S[j].substr(1, 2)) { ts.add_clause(i, 1, j, 1); } if (S[i].substr(1, 2) == S[j].substr(0, 2)) { ts.add_clause(i, 1, j, 0); } if (S[i].substr(0, 2) == S[j].substr(1, 2)) { ts.add_clause(i, 0, j, 1); } if (S[i].substr(0, 2) == S[j].substr(0, 2)) { ts.add_clause(i, 0, j, 0); } } bool C = ts.satisfiable(); if(!C)cout<< "Impossible" << endl; else { auto v = ts.answer(); rep(i, N) { if (v[i]) { cout << S[i].substr(0, 2) << " " << S[i].substr(2, 1) << endl; } else { cout << S[i].substr(0, 1) << " " << S[i].substr(1,2) << endl; } } } }