#include using namespace std; #define _p(...) (void)printf(__VA_ARGS__) #define forr(x,arr) for(auto&& x:arr) #define _overload3(_1,_2,_3,name,...) name #define _rep2(i,n) _rep3(i,0,n) #define _rep3(i,a,b) for(int i=int(a);i=int(a);i--) #define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__) #define all(x) (x).begin(), (x).end() #define bit(n) (1LL<<(n)) #define sz(x) ((int)(x).size()) #define fst first #define snd second using ll=long long;using pii=pair; using vb=vector;using vs=vector; using vi=vector;using vvi=vector;using vvvi=vector; using vl=vector;using vvl=vector;using vvvl=vector; using vd=vector;using vvd=vector;using vvvd=vector; using vpii=vector;using vvpii=vector;using vvvpii=vector; templateT read(){T t;cin>>t;return t;} templateostream&operator<<(ostream&o,const pair&p){o<<'('< fix; vector ans; set used; vector s1; vector s2; vector s3; vector s4; void output() { rep(i, n) { if (ans[i] == 12) { cout << s1[i] << ' ' << s2[i] << endl; } else if (ans[i] == 34) { cout << s3[i] << ' ' << s4[i] << endl; } else { assert(false); } } exit(0); } void backtrack(int i) { if (i >= n) { output(); } if (ans[i] != -1) backtrack(i + 1); if (used.count(s1[i]) == 0 && used.count(s2[i]) == 0) { if ((fix.count(s1[i]) == 0 || fix[s1[i]] == i) && (fix.count(s2[i]) == 0 || fix[s2[i]] == i)) { used.insert(s1[i]); used.insert(s2[i]); ans[i] = 12; backtrack(i+1); ans[i] = -1; used.erase(s1[i]); used.erase(s2[i]); } } if (used.count(s3[i]) == 0 && used.count(s4[i]) == 0) { if ((fix.count(s3[i]) == 0 || fix[s4[i]] == i) && (fix.count(s3[i]) == 0 || fix[s4[i]] == i)) { used.insert(s3[i]); used.insert(s4[i]); ans[i] = 34; backtrack(i+1); ans[i] = -1; used.erase(s3[i]); used.erase(s4[i]); } } } void Main() { n = read(); ans.resize(n, -1); rep(i, n) { string s = read(); s1.push_back(s.substr(0, 1)); s2.push_back(s.substr(1, 2)); s3.push_back(s.substr(0, 2)); s4.push_back(s.substr(2, 1)); if (s[0] == s[2]) { if (s[0] == s[1]) { if (fix.count(s1[i])) panic(); if (fix.count(s2[i])) panic(); fix.emplace(s1[i], i); fix.emplace(s2[i], i); used.insert(s1[i]); used.insert(s2[i]); ans[i] = 12; } else { if (fix.count(s1[i])) panic(); fix.emplace(s1[i], i); } } } //cout << "s1:"; rep(ii,sz(s1)) cout << ' ' << s1[ii]; cout << endl; //cout << "s2:"; rep(ii,sz(s2)) cout << ' ' << s2[ii]; cout << endl; //cout << "s3:"; rep(ii,sz(s3)) cout << ' ' << s3[ii]; cout << endl; //cout << "s4:"; rep(ii,sz(s4)) cout << ' ' << s4[ii]; cout << endl; //forr(si, fix) cout << si.fst << ", " << si.snd << endl; backtrack(0); panic(); } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Main(); return 0; }