#include using namespace std; string tb1 = "A123456789TJQK"; string tb2 = "DCHS"; bool cmp(string a,string b){ a[0] = 'A'+tb2.find(a[0]); a[1] = 'A'+tb1.find(a[1]); b[0] = 'A'+tb2.find(b[0]); b[1] = 'A'+tb1.find(b[1]); return a < b; } int main(){ int N; string s; vector S; cin >> N; for(int i = 0 ; i < N ; i++){ cin >> s; S.push_back(s); } sort(S.begin(),S.end(),cmp); for(int i = 0 ; i < S.size() ; i++){ cout << S[i]; if( i + 1 == S.size() ) cout << endl; else cout << " "; } }