#include using namespace std; #define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define rep(i,n) repl(i,0,n) #define mp(a,b) make_pair((a),(b)) #define pb(a) push_back((a)) #define all(x) (x).begin(),(x).end() #define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x)) #define fi first #define se second #define dbg(x) cout<<#x" = "<<((x))< ostream& operator<<(ostream& o, const pair &p){o<<"("< ostream& operator<<(ostream& o, const vector &v){o<<"[";for(T t:v){o<> &G; vector> &rG; vector used; vector vs; vector cmp; // 頂点iが属するSCCのID int n; void dfs(int v){ used[v] = true; for(auto to : G[v]) if(!used[to]) dfs(to); vs.pb(v); } void rdfs(int v, int k){ used[v] = true; cmp[v] = k; for(auto to : rG[v]) if(!used[to]) rdfs(to, k); } public: int gc = 0; // group count SCC(vector> &g, vector> &r) : G(g), rG(r){ n = G.size(); used = vector(n,false); cmp.resize(n); rep(i,n) if(!used[i]) dfs(i); fill(all(used), false); for(int i = vs.size()-1; i>=0; i--) if(!used[vs[i]]) rdfs(vs[i], gc++); } inline bool same(int i, int j){ return cmp[i]==cmp[j]; } inline int operator[](int i){ return cmp[i]; } }; // 2-SAT O(M + N) M:# of vars, N:# of clauses class TwoSat { private: vector > vec; vector > rev; vector res; int v; public: TwoSat(int n) : v(n){ vec.resize(2*v); rev.resize(2*v); res.resize(v); } inline void add_edge(int a, bool ab, int b, bool bb){ // add (a -> b) int va = a + (ab?0:v); int vb = b + (bb?0:v); vec[va].pb(vb); rev[vb].pb(va); } inline void add(int a, bool ab, int b, bool bb){ // a or b <-> ((!a -> b) and (!b -> a)) add_edge(a, !ab, b, bb); add_edge(b, !bb, a, ab); } bool exec(){ SCC scc(vec, rev); rep(i,v){ if(scc.same(i, i+v)) return false; res[i] = scc[i]>scc[i+v]; } return true; } inline int operator[](int i){ return res[i]; } }; bool solve(){ int n; cin>>n; vector vec(n); rep(i,n) cin>>vec[i]; if(n > 52) return false; map> m; TwoSat sat(2*n); // 2*i:iを前で切る,2*i+1:iを後ろで切る rep(i,n) sat.add(2*i,true,2*i+1,true); rep(i,n){ m[vec[i].substr(0,1)].pb(2*i); m[vec[i].substr(1,2)].pb(2*i); m[vec[i].substr(0,2)].pb(2*i+1); m[vec[i].substr(2,1)].pb(2*i+1); } for(auto &p : m){ auto &v = p.second; int l=v.size(); rep(i,l)rep(j,l)if(i!=j) sat.add_edge(v[i],true,v[j],false); } if(!sat.exec()) return false; rep(i,n){ if(sat[2*i]) cout << vec[i].substr(0,1) << " " << vec[i].substr(1,2) << endl; else cout << vec[i].substr(0,2) << " " << vec[i].substr(2,1) << endl; } return true; } int main(){ if(!solve()) cout << "Impossible" << endl; return 0; }