#include using namespace std; using i64 = long long; #define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++) int N; vector u; #include #include #include #include #include #include #include using namespace std; typedef long long i64; typedef long double ld; typedef pair P; vector sccd(const vector> & G){ vector> rG(G.size()); for(int i = 0;i < G.size();i++){ for(int to : G[i]) rG[to].push_back(i); } vector vis(G.size(),false); vector vs; vector res(G.size(),-1); function dfs = [&](int v){ vis[v] = true; for(int to : G[v]){ if(!vis[to]) dfs(to); } vs.push_back(v); }; function rdfs = [&](int v,int k){ vis[v] = true; res[v] = k; for(int to : rG[v]){ if(!vis[to]) rdfs(to,k); } }; for(int i = 0;i < G.size();i++){ if(!vis[i]) dfs(i); } vis.assign(G.size(),false); int k = 0; reverse(vs.begin(),vs.end()); for(int i = 0;i < G.size();i++){ if(!vis[vs[i]]) rdfs(vs[i],k++); } return res; } int main(){ cin >> N; u.resize(N); if(N > 52){ cout << "Impossible" << endl; return 0; } rep(i,0,N - 1){ cin >> u[i]; } vector> G(N * 2); rep(i,0,N - 1){ rep(j,i + 1,N - 1){ rep(k,0,1){ rep(l,0,1){ string s2 = u[i].substr(k,2); string s1 = u[i].substr((1 - k) * 2,1); string t2 = u[j].substr(l,2); string t1 = u[j].substr((1 - l) * 2,1); if(s2 == t2 || s1 == t1){ G[i + N * k].push_back(j + N * (1 - l)); G[j + N * l].push_back(i + N * (1 - k)); } } } } } auto res = sccd(G); rep(i,0,N - 1){ if(res[i] == res[i + N]){ cout << "Impossible" << endl; return 0; } } rep(i,0,N - 1){ string s1,s2; if(res[i] > res[i + N]){ s1 = u[i].substr(0,2); s2 = u[i].substr(2,1); } else{ s1 = u[i].substr(0,1); s2 = u[i].substr(1,2); } cout << s1 << " " << s2 << endl; } }