#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; vector > v; string s = "DCHS"; string T = "TJQK"; int main(){ int n; cin >> n; for (int i = 0; i < n; i++){ string ss; cin >> ss; int ind = s.find(ss[0]); int ind2 = 0; if (isdigit(ss[1])){ ind2 = ss[1]-'0'; } else{ if (ss[1] == 'A'){ ind2 = 1; } else{ ind2 = T.find(ss[1]) + 10; } } v.push_back(make_pair(ind, ind2)); } sort(v.begin(), v.end()); for (int i = 0; i < v.size(); i++){ if (i){ cout << " "; } cout << s[v[i].first]; if (v[i].second == 1){ cout << "A"; } else{ if (v[i].second >= 10){ cout << T[v[i].second - 10]; } else{ cout << v[i].second - '0'; } } } cout << endl; return 0; }