#include "bits/stdc++.h" using namespace std; using ll = long long; const double pi = acos(-1); #define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++) #define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--) #define REP(i,n) FOR(i,0,n) #define RREP(i,n) RFOR(i,0,n) #define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME #define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__) #define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__) template ostream& operator<<(ostream& os, const vector& v) { REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os; } template ostream& operator<<(ostream& os, const vector>& v) { REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os; } const ll INF = 1LL << 60; ll MOD = 1000000007; ll _MOD = 1000000009; double EPS = 1e-10; #define int long long inline void my_io() { std::ios::sync_with_stdio(false); std::cin.tie(0); cout << fixed << setprecision(16); //cout << setprecision(10) << scientific << ans << endl; } #define ALL(x) (x).begin(),(x).end() class SAT { public: static const int MAX_V = 2 << 10; vector g[MAX_V], rg[MAX_V], vs; bool used[MAX_V]; int cmp[MAX_V], V, N; SAT(int n) : V(2 * n), N(n) { ; } //(X_2 | !X_5) -> add_closure(2, 1, 5, 0) void add_closure(int i, bool bi, int j, bool bj) { add_edge(i + N * !bi, j + N * bj); add_edge(j + N * !bj, i + N * bi); } void add_edge(int from, int to) { g[from].push_back(to); rg[to].push_back(from); } void dfs(int v) { used[v] = true; for (int i : g[v]) if (!used[i]) dfs(i); vs.push_back(v); } void rdfs(int v, int k) { used[v] = true; cmp[v] = k; for (int i : rg[v]) if (!used[i]) rdfs(i, k); } //no solution: {}, else {1, 0, 1,...} vector solve() { memset(used, 0, sizeof(used)); vs.clear(); REP(v, V) if (!used[v]) dfs(v); memset(used, 0, sizeof(used)); reverse(ALL(vs)); int k = 0; for (int i : vs) if (!used[i]) rdfs(i, k++); vector res; REP(i, N) if (cmp[i] == cmp[i + N]) return res; REP(i, N) { if (cmp[i] > cmp[N + i]) res.push_back(true); else res.push_back(false); } return res; } }; signed main() { ll n; string u; cin >> n; if (n > 60) { cout << "Impossible" << endl; return 0; } vector v; REP(i, n) { cin >> u; v.push_back(u); } SAT s(n); string u1, u2; REP(i, n) { FOR(j, i + 1, n) { u1 = v[i]; u2 = v[j]; if (u1[0] == u2[0] || u1.substr(1, 2) == u2.substr(1, 2)) { s.add_closure(i, 0, j, 0); } if (u1[0] == u2[2] || u1.substr(1, 2) == u2.substr(0, 2)) { s.add_closure(i, 0, j, 1); } if (u1[2] == u2[0] || u1.substr(0, 2) == u2.substr(1, 2)) { s.add_closure(i, 1, j, 0); } if (u1[2] == u2[2] || u1.substr(0, 2) == u2.substr(0, 2)) { s.add_closure(i, 1, j, 1); } } } vector ans = s.solve(); if (ans.size()) { REP(i, n) { if (ans[i]) { cout << v[i][0]; } else { cout << v[i].substr(0, 2); } cout << " "; if (ans[i]) { cout << v[i].substr(1, 2); } else { cout << v[i][2]; } cout << endl; } } else { cout << "Impossible" << endl; } }