// WA #include #include #include #include #include #include #include #define repeat(i,n) for (int i = 0; (i) < int(n); ++(i)) #define repeat_from(i,m,n) for (int i = (m); (i) < int(n); ++(i)) #define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) using namespace std; int main() { int n; cin >> n; vector s(n); repeat (i,n) cin >> s[i]; assert (1 <= n and n <= 100000); repeat (i,n) { assert (s[i].length() == 3); for (char c : s[i]) assert ('A' <= c and c <= 'Z' or 'a' <= c and c <= 'z'); } vector result; if (n <= (26*2)*(26*2+1)) { map cnt; repeat (i,n) { cnt[s[i].substr(0, 1)] += 1; cnt[s[i].substr(1, 2)] += 1; cnt[s[i].substr(0, 2)] += 1; cnt[s[i].substr(2, 1)] += 1; } auto score = [&](pair it) { int i; bool p; tie(i, p) = it; int a, b; if (p) { a = cnt[s[i].substr(0, 1)]; b = cnt[s[i].substr(1, 2)]; } else { a = cnt[s[i].substr(0, 2)]; b = cnt[s[i].substr(2, 1)]; } return a + b; }; vector > xs; repeat (i,n) repeat (p,2) xs.emplace_back(i, p); result.resize(n); set used; vector decided(n); while (not xs.empty()) { auto it = whole(min_element, xs, [&](auto x, auto y) { return score(x) < score(y); }); int i; bool p; tie(i, p) = *it; xs.erase(it); if (decided[i]) continue; string a, b; if (p) { a = cnt[s[i].substr(0, 1)]; b = cnt[s[i].substr(1, 2)]; } else { a = cnt[s[i].substr(0, 2)]; b = cnt[s[i].substr(2, 1)]; } if (not used.count(a) and not used.count(b)) { result[i] = p; decided[i] = true; used.insert(a); used.insert(b); } } repeat (i,n) { if (not decided[i]) { result.clear(); break; } } } if (result.empty()) { cout << "Impossible" << endl; } else { repeat (i,n) { if (result[i]) { cout << s[i][0] << ' ' << s[i][1] << s[i][2] << endl; } else { cout << s[i][0] << s[i][1] << ' ' << s[i][2] << endl; } } } return 0; }