#include using namespace std; struct StronglyConnectedComponent { const int V; vector> G, revG; vector id; StronglyConnectedComponent(const int V) : V(V), G(vector>(V, vector())), revG(vector>(V, vector())), id(vector(V)) {} void addEdge(int from, int to) { G[from].push_back(to); revG[to].push_back(from); } void build() { vector used(V, false); stack st; for(int from = 0; from < V; ++from) { if(not used[from]) { dfs(from, used, st); } } int num = 0; while(st.size()) { int from = st.top(); st.pop(); if(used[from]) { revdfs(from, num, used); ++num; } } } void dfs(int from, vector &used, stack &st) { used[from] = true; for(int to : G[from]) { if(not used[to]) { dfs(to, used, st); } } st.push(from); } void revdfs(int from, int num, vector &used) { used[from] = false; id[from] = num; for(int to : revG[from]) { if(used[to]) { revdfs(to, num, used); } } } int get(int x) { return id[x]; } }; struct TwoSatisfiability { const int V; vector> G; vector pos; StronglyConnectedComponent scc; TwoSatisfiability(const int V) : V(V), G(vector>(2 * V, vector())), pos(vector(2 * V)), scc(StronglyConnectedComponent(2 * V)) {} // a or b void addEdge(int a, bool apos, int b, bool bpos) { if(not apos) a += V; if(not bpos) b += V; scc.addEdge((a + V) % (2 * V), b); // not a -> b scc.addEdge((b + V) % (2 * V), a); // not b -> a } bool solve() { scc.build(); for(int i = 0; i < V; ++i) { if(scc.get(i) == scc.get(i + V)) { return false; } pos[i] = (scc.get(i) > scc.get(i + V)); } return true; } bool get(int x) { return pos[x]; } }; int main() { int n; cin >> n; string u[n]; for(int i = 0; i < n; ++i) { cin >> u[i]; } if(n > 100) { cout << "Impossible" << '\n'; return 0; } TwoSatisfiability sat(n); for(int i = 0; i < n; ++i) { for(int j = i + 1; j < n; ++j) { for(int mask = 0; mask < (1 << 2); ++mask) { bool ipos = (mask & 1); bool jpos = ((mask >> 1) & 1); int sin = 1; if(not ipos) { sin = 2; } int sjn = 1; if(not jpos) { sjn = 2; } set st; st.insert(u[i].substr(0, sin)); st.insert(u[i].substr(sin)); st.insert(u[j].substr(0, sjn)); st.insert(u[j].substr(sjn)); // 衝突するとき // not (A and B) // => (not A) or (not B) if(st.size() < 4) { sat.addEdge(i, not ipos, j, not jpos); } } } } if(not sat.solve()) { cout << "Impossible" << '\n'; return 0; } for(int i = 0; i < n; ++i) { if(sat.get(i)) { cout << u[i].substr(0, 1) << " " << u[i].substr(1) << '\n'; } else { cout << u[i].substr(0, 2) << " " << u[i].substr(2) << '\n'; } } return 0; }