#include using namespace std; #define INF 100000000 #define YJ 1145141919 #define INF_INT_MAX 2147483647 #define INF_LL_MAX 9223372036854775807 #define EPS 1e-10 #define Pi acos(-1) #define LL long long #define ULL unsigned long long #define LD long double using namespace std; //変数は0-index //trueなx_iはi , falseなx_iはi+XSizeのインデックスで管理する class SAT_2{ public: SAT_2(int aN) { init(aN); } //変数の数 void init(int aN) { XSize = aN; VecSize = 2 * XSize; Edge.resize(VecSize); rEdge.resize(VecSize); used.resize(VecSize); vs.clear(); cmp.resize(VecSize); } int revTF(int a) { return (a + XSize) % (2 * XSize); } //節を登録 //(¬x_i v x_j)ならreg(i + XSize, j)を呼び出す void reg(int l, int r) { int tmpL = l, tmpR = r; tmpL = revTF(tmpL); Edge[tmpL].push_back(tmpR); rEdge[tmpR].push_back(tmpL); tmpL = r, tmpR = l; tmpL = revTF(tmpL); Edge[tmpL].push_back(tmpR); rEdge[tmpR].push_back(tmpL); } void dfs(int v) { used[v] = true; for (int i = 0; i < Edge[v].size(); i++) { if(!used[Edge[v][i]]){ dfs(Edge[v][i]); } } vs.push_back(v); } void rdfs(int v, int k){ used[v] = true; cmp[v] = k; for (int i = 0; i < rEdge[v].size(); i++) { if(!used[rEdge[v][i]]){ rdfs(rEdge[v][i], k); } } } int scc() { for (int i = 0; i < used.size(); i++) { used[i] = false; } vs.clear(); for (int i = 0; i < VecSize; i++) { if(!used[i]) dfs(i); } for (int i = 0; i < used.size(); i++) { used[i] = false; } int k = 0; for (int i = vs.size() - 1; 0 <= i; i--) { if(!used[vs[i]]){ rdfs(vs[i], k++); } } return k; } bool checkSatisfy() { scc(); for (int i = 0; i < XSize; i++) { if(cmp[i] == cmp[i+XSize]){ return false; } } return true; } //x_lの真偽値を取得 たぶんまだ出来てない bool getTF(int l) { assert(0 <= l && l < XSize); return cmp[l] > cmp[l+XSize]; } void debug() { for (int i = 0; i < VecSize; i++) { cerr << cmp[i] << endl; } } private: vector> Edge; vector> rEdge; vector used; vector vs; //帰りがけ順の並び vector cmp; //属する連結成分のトポロジカル順序 int XSize; int VecSize; }; #define MAX_N 10005 int N; string U[MAX_N]; int main() { cin >> N; for (int i = 0; i < N; i++) { cin >> U[i]; } if(N > 52){ cout << "Impossible" << endl; return 0; } SAT_2 sat(N); for (int i = 0; i < N; i++) { for (int j = i+1; j < N; j++) { if(i == j){ continue; } string A1, A2, B1, B2; A1 = U[i].substr(0,1), A2 = U[i].substr(1, 2), B1 = U[j].substr(0,1), B2 = U[j].substr(1,2); if(A1 == B1 || A2 == B2){ sat.reg(i+N, j+N); } A1 = U[i].substr(0,1), A2 = U[i].substr(1, 2), B1 = U[j].substr(0,2), B2 = U[j].substr(2,1); if(A1 == B2 || A2 == B1){ sat.reg(i+N, j); } A1 = U[i].substr(0,2), A2 = U[i].substr(2, 1), B1 = U[j].substr(0,1), B2 = U[j].substr(1,2); if(A1 == B2 || A2 == B1){ sat.reg(i, j+N); } A1 = U[i].substr(0,2), A2 = U[i].substr(2, 1), B1 = U[j].substr(0,2), B2 = U[j].substr(2,1); if(A1 == B1 || A2 == B2){ sat.reg(i, j); } } } if(!sat.checkSatisfy()){ cout << "Impossible" << endl; } else{ for (int i = 0; i < N; i++) { if(sat.getTF(i)){ cout << U[i].substr(0,1) << " " << U[i].substr(1, 2) << endl; } else{ cout << U[i].substr(0,2) << " " << U[i].substr(2, 1) << endl; } } } return 0; }