#include using namespace std; bool comp(const pair x, const pair y) { int xx, yy; string t = "DCHS", u = "A23456789TJQK"; for(int i = 0; i < 4; i++) { if(x.first == t[i]) xx = i; if(y.first == t[i]) yy = i; } xx *= 10; yy *= 10; for(int i = 0; i < u.size(); i++) { if(x.second == u[i]) xx += i; if(y.second == u[i]) yy += i; } return xx < yy; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector> a(n); for(int i = 0; i < n; i++) { string s; cin >> s; a[i].first = s[0]; a[i].second = s[1]; } sort(a.begin(), a.end(), comp); for(int i = 0; i < n; i++) { if(i > 0) cout << " "; cout << a[i].first << a[i].second; } cout << '\n'; return 0; }