#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define _overload3(_1,_2,_3,name,...) name #define _rep(i,n) repi(i,0,n) #define repi(i,a,b) for(ll i=ll(a);ibool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b void cins(itr first,itr last){ for (auto i = first;i != last;i++){ cin >> (*i); } } template void array_output(itr start,itr goal){ string ans = "",k = " "; for (auto i = start;i != goal;i++) ans += to_string(*i)+k; if (!ans.empty()) ans.pop_back(); PRINT(ans); } ll gcd(ll a, ll b) { return a ? gcd(b%a,a) : b; } const ll INF = 1e16; const ll MOD = 1000000007; typedef pair P; const ll MAX = 200005; constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1}; constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1}; class StronglyConnectedComponents{ private: int siz; vector> g,rg; vector vs,cmp; vector done; public: StronglyConnectedComponents(int n){ siz = n; g.resize(n); rg.resize(n); cmp.resize(n); } void add_edge(int from,int to){ g[from].push_back(to); rg[to].push_back(from); } void dfs(int v){ done[v] = true; for(int u:g[v]){ if (!done[u]) dfs(u); } vs.push_back(v); } void rdfs(int v,int k){ done[v] = true; cmp[v] = k; for(int u:rg[v]){ if (!done[u]) rdfs(u,k); } } int scc(){ done.assign(siz,false); rep(v,siz) if (!done[v]) dfs(v); done.assign(siz,false); int k = 0; for (int v = siz-1;v >= 0;v--) if (!done[vs[v]]) rdfs(vs[v],k++); return k; } int operator[](int k){ return cmp[k]; } }; int main(){ cin.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; vector u(n); cins(all(u)); StronglyConnectedComponents g(2*n); rep(i,n-1){ rep(j,i+1,n){ string s = u[i],t = u[j]; if (s[0] == t[0] || s.substr(1,2) == t.substr(1,2)){ g.add_edge(i,j+n); g.add_edge(j,i+n); } if (s[0] == t[2] || s.substr(1,2) == t.substr(0,2)){ g.add_edge(i,j); g.add_edge(j+n,i+n); } if (s[2] == t[0] || s.substr(0,2) == t.substr(1,2)){ g.add_edge(j,i); g.add_edge(i+n,j+n); } if (s[2] == t[2] || s.substr(0,2) == t.substr(0,2)){ g.add_edge(i+n,j); g.add_edge(j+n,i); } } } g.scc(); rep(i,n){ if (g[i] == g[i+n]){ PRINT("Impossible"); return 0; } } rep(i,n){ if (g[i] > g[i+n]){ cout << u[i][0] << " " << u[i].substr(1,2) << '\n'; } else{ cout << u[i].substr(0,2) << " " << u[i][2] << '\n'; } } }