#include using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(c) begin(c), end(c) #define dump(x) cerr << __LINE__ << ":\t" #x " = " << x << endl using Weight = int; using Capacity = int; struct Edge { int src, dst; Weight weight; Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {} }; using Edges = vector; using Graph = vector; using Array = vector; using Matrix = vector; vector kosaraju(const Graph &g) { int n = g.size(), sz = 0; Graph rg(n); vector stk, cmp(n, -1), added(n), visited(n), ord(n); for (auto &es : g) { for (auto &e : es) rg[e.dst].emplace_back(e.dst, e.src, e.weight); sz += es.size(); } stk.resize(n + sz); sz = 0; for (int i = 0; i < n; i++) { if (visited[i]) continue; int s = 0; stk[s++] = i; while (s != 0) { int v = stk[s - 1]; visited[v] = true; bool pushed = false; for (auto &e : g[v]) { int dst = e.dst; if (!visited[dst]) { stk[s++] = dst; pushed = true; } } if (pushed) continue; int t = stk[s - 1]; if (!added[t]) { added[t] = true; ord[n - ++sz] = t; } --s; } } int k = 0; for (int &u : ord) { if (cmp[u] != -1) continue; int s = 0; stk[s++] = u; while (s != 0) { int v = stk[--s]; cmp[v] = k; for (auto &e : rg[v]) { int d = e.dst; if (cmp[d] == -1) stk[s++] = d; } } ++k; } return cmp; } int main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin >> n; if(n > 2756){ cout << "Impossible" << endl; exit(0); } vector ss(n); rep(i, n) cin >> ss[i]; int nn = n+n; Graph g(nn); auto sep = [&](int u, int v){ int iu = (u+n) % nn; int iv = (v+n) % nn; g[u].emplace_back(u, v, 1); g[iv].emplace_back(iv, iu, 1); }; vector a(n), ab(n), bc(n), c(n); rep(i, n){ string &s = ss[i]; a[i] = s.substr(0, 1); ab[i] = s.substr(0, 2); bc[i] = s.substr(1); c[i] = s.substr(2); } rep(i, n) rep(j, i){ if(a[i] == a[j] || bc[i] == bc[j]) sep(i, j+n); if(a[i] == c[j] || bc[i] == ab[j]) sep(i, j); if(c[i] == a[j] || ab[i] == bc[j]) sep(i+n, j+n); if(c[i] == c[j] || ab[i] == ab[j]) sep(i+n, j); } vector cmp = kosaraju(g); rep(i, n){ if(cmp[i] == cmp[i+n]){ cout << "Impossible" << '\n'; exit(0); } } rep(i, n){ if(cmp[i] < cmp[i+n]) cout << ab[i] << ' ' << c[i] << '\n'; else cout << a[i] << ' ' << bc[i] << '\n'; } }