#include using namespace std; #define ll long long #define pii pair #define pll pair #define fi first #define se second const int N = 2e5 + 5, M = 1e6 + 5; const int inf = 1e9, mod = 998244353; const ll INF = 1e18; int n, m; int head[N], idx; int dfn[N], low[N], tot; int bel[N], scc, stk[N], tp; bool ins[N]; struct edge{ int to, nxt; } e[M << 1]; string s[N]; void add(int u, int v){ e[++ idx] = {v, head[u]}, head[u] = idx; } void Tarjan(int u){ dfn[u] = low[u] = ++ tot; ins[u] = true, stk[++ tp] = u; for (int i = head[u]; ~i; i = e[i].nxt){ int v = e[i].to; if (!dfn[v]) Tarjan(v), low[u] = min(low[u], low[v]); else if (ins[v]) low[u] = min(low[u], dfn[v]); } if (dfn[u] == low[u]){ scc ++; int now; do{ now = stk[tp -- ]; ins[now] = false; bel[now] = scc; } while (now != u); } } void init(){ idx = -1; memset(head, -1, sizeof head); } void solve(){ cin >> n; if (n > 52){ cout << "Impossible\n"; return ; } for (int i = 1; i <= n; i ++ ) cin >> s[i]; for (int i = 1; i <= n; i ++ ) for (int j = 1; j <= n; j ++ ){ if (i == j) continue; { string a; a += s[i][0]; string b; b += s[i][1], b += s[i][2]; string c; c += s[j][0]; string d; d += s[j][1], d += s[j][2]; if (a == b || a == c || a == d || b == c || b == d || c == d) add(2 * i, 2 * j - 1), add(2 * j, 2 * i - 1); } { string a; a += s[i][0]; string b; b += s[i][1], b += s[i][2]; string c; c += s[j][0], c += s[j][1]; string d; d += s[j][2]; if (a == b || a == c || a == d || b == c || b == d || c == d) add(2 * i, 2 * j), add(2 * j - 1, 2 * i - 1); } { string a; a += s[i][0], a += s[i][1]; string b; b += s[i][2]; string c; c += s[j][0]; string d; d += s[j][1], d += s[j][2]; if (a == b || a == c || a == d || b == c || b == d || c == d) add(2 * i - 1, 2 * j - 1), add(2 * j, 2 * i); } { string a; a += s[i][0], a += s[i][1]; string b; b += s[i][2]; string c; c += s[j][0], c += s[j][1]; string d; d += s[j][2]; if (a == b || a == c || a == d || b == c || b == d || c == d) add(2 * i - 1, 2 * j), add(2 * j - 1, 2 * i); } } for (int i = 1; i <= n + n; i ++ ) if (!dfn[i]) Tarjan(i); for (int i = 1; i <= n; i ++ ){ if (bel[i * 2 - 1] == bel[i * 2]){ cout << "Impossible\n"; return ; } } for (int i = 1; i <= n; i ++ ){ if (bel[i * 2 - 1] < bel[i * 2]) cout << s[i][0] << s[i][1] << " " << s[i][2] << "\n"; else cout << s[i][0] << " " << s[i][1] << s[i][2] << "\n"; } } signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T = 1; //cin >> T; while (T -- ) init(), solve(); }