//https://ncode.syosetu.com/n4830bu/267/ #include using namespace std; int main() { int N; cin >> N; vector V(N); for (auto&& x : V) { cin >> x; } auto maine = [](string s) { int ret = 0; if (s[0] == 'D') ret = 0; else if (s[0] == 'C') ret = 100; else if (s[0] == 'H') ret = 200; else if (s[0] == 'S') ret = 300; else assert(false); if (isdigit(s[1])) ret += s[1] - '0'; else if (s[1] == 'A') ret += 1; else if (s[1] == 'T') ret += 10; else if (s[1] == 'J') ret += 11; else if (s[1] == 'Q') ret += 12; else if (s[1] == 'K') ret += 13; else assert(false); return ret; }; sort(V.begin(), V.end(), [&](string x, string y) { return maine(x) < maine(y); }); for (int i = 0; i < N; i++) { cout << V[i] << " \n"[i == N - 1]; } }