#include using namespace std; using ll = long long; #define rep(i, s, e) for (int i = (int)s; i < (int)e; ++i) #define all(a) (a).begin(), (a).end() const ll mod = 1e9 + 7; int main() { cin.tie(nullptr); int N; cin >> N; vector> card(N, {-1, -1}); rep(i, 0, N) { char m, n; cin >> m >> n; if (m == 'D') card[i].first = 0; if (m == 'C') card[i].first = 1; if (m == 'H') card[i].first = 2; if (m == 'S') card[i].first = 3; if ('2' <= n && n <= '9') card[i].second = n - '1'; else { if (n == 'A') card[i].second = 0; if (n == 'T') card[i].second = 9; if (n == 'J') card[i].second = 10; if (n == 'Q') card[i].second = 11; if (n == 'K') card[i].second = 12; } } sort(all(card)); vector mark = {'D', 'C', 'H', 'S'}; vector num = {'A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K'}; rep(i, 0, N) { cout << mark[card[i].first] << num[card[i].second]; if (i == N - 1) cout << '\n'; else cout << ' '; } }