#include using namespace std; typedef long long ll; typedef vector vi; typedef vector vl; typedef pair pii; typedef pair pll; typedef int _loop_int; #define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i) #define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i) #define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i) #define DEBUG(x) cout<<#x<<": "<>u[i]; if(n>=53){ puts("Impossible"); return 0; } // cut a/bc -> true // cut ab/c -> false bool flag = true; REP(i,n)used[i] = -1; REP(i,n)REP(j,i){ string a = u[i].substr(0,1); string b = u[i].substr(1,1); string c = u[i].substr(2,1); string x = u[j].substr(0,1); string y = u[j].substr(1,1); string z = u[j].substr(2,1); bool tt = (a!=x)&&(b+c!=y+z); bool tf = (a!=z)&&(b+c!=x+y); bool ft = (a+b!=y+z)&&(c!=x); bool ff = (a+b!=x+y)&&(c!=z); // printf("%d %d -> %d %d %d %d\n",i,j,tt,tf,ft,ff); if(!tt){ g[2*i][2*j+1] = true; g[2*j][2*i+1] = true; } if(!tf){ g[2*i][2*j] = true; g[2*j+1][2*i+1] = true; } if(!ft){ g[2*i+1][2*j+1] = true; g[2*j][2*i] = true; } if(!ff){ g[2*i+1][2*j] = true; g[2*j+1][2*i] = true; } } // REP(i,2*n){ // REP(j,2*n)printf("%2d",g[i][j]); // puts(""); // }puts(""); REP(k,2*n)REP(i,2*n)REP(j,2*n)g[i][j]=g[i][j]||(g[i][k]&&g[k][j]); // REP(i,2*n){ // REP(j,2*n)printf("%2d",g[i][j]); // puts(""); // } REP(i,n)if(g[2*i][2*i+1] && g[2*i+1][2*i])flag = false; if(!flag){ puts("Impossible"); }else{ REP(i,n)if(used[i]==-1)dfs(i,0); REP(i,n){ if(used[i]==0){ printf("%s %s\n",u[i].substr(0,1).c_str(), u[i].substr(1,2).c_str()); }else{ printf("%s %s\n",u[i].substr(0,2).c_str(), u[i].substr(2,1).c_str()); } } } return 0; }