#include #include #include using namespace std; int main(){ vector v; int n; cin >> n; for(int i = 0;i < n;i++){ string s; cin >> s; int num; if(isdigit(s[1])) num = s[1] - '0'; else if(s[1] == 'A') num = 1; else if(s[1] == 'T') num = 10; else if(s[1] == 'J') num = 11; else if(s[1] == 'Q') num = 12; else if(s[1] == 'K') num = 13; if(s[0] == 'C') num += 13; else if(s[0] == 'H') num += 26; else if(s[0] == 'S') num += 39; v.push_back(num); } stable_sort(v.begin(),v.end()); for(int i = 0;i < v.size();i++){ if(v[i] / 13 == 0){ cout << 'D'; if(v[i] != 1 && v[i] != 10 && v[i] != 11 && v[i] != 12 && v[i] != 13) cout << v[i]; else if(v[i] == 1) cout << 'A'; else if(v[i] == 10) cout << 'T'; else if(v[i] == 11) cout << 'J'; else if(v[i] == 12) cout << 'Q'; else if(v[i] == 13) cout << 'K'; }else if(v[i] / 13 == 1){ cout << 'C'; v[i] %= 13; if(v[i] != 1 && v[i] != 10 && v[i] != 11 && v[i] != 12 && v[i] != 13) cout << v[i]; else if(v[i] == 1) cout << 'A'; else if(v[i] == 10) cout << 'T'; else if(v[i] == 11) cout << 'J'; else if(v[i] == 12) cout << 'Q'; else if(v[i] == 13) cout << 'K'; }else if(v[i] / 13 == 2){ cout << 'H'; v[i] %= 13; if(v[i] != 1 && v[i] != 10 && v[i] != 11 && v[i] != 12 && v[i] != 13) cout << v[i]; else if(v[i] == 1) cout << 'A'; else if(v[i] == 10) cout << 'T'; else if(v[i] == 11) cout << 'J'; else if(v[i] == 12) cout << 'Q'; else if(v[i] == 13) cout << 'K'; }else{ cout << 'S'; v[i] %= 13; if(v[i] != 1 && v[i] != 10 && v[i] != 11 && v[i] != 12 && v[i] != 13) cout << v[i]; else if(v[i] == 1) cout << 'A'; else if(v[i] == 10) cout << 'T'; else if(v[i] == 11) cout << 'J'; else if(v[i] == 12) cout << 'Q'; else if(v[i] == 13) cout << 'K'; } cout << ' '; } cout << endl; }