#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); int N; cin >> N; vector> A(N); rep(i,N) { char c; cin >> c; string s; cin >> s; int a = [c]() { if(c == 'D') return 0; if(c == 'C') return 1; if(c == 'H') return 2; if(c == 'S') return 3; return -1; }(); int b = [s]() { if(s == "A") return 1; if(s == "T") return 10; if(s == "J") return 11; if(s == "Q") return 12; if(s == "K") return 13; return stoi(s); }(); A[i] = {a, b, c, s}; } sort(A.begin(), A.end()); for(auto [_, __, m, n] : A) cout << m << n << " "; cout << endl; }