#include #include #include #include #include #include #include using namespace std; static const int MAX_N = 1000005; int main() { int n; string s; vector < pair, string > >v; cin >> n; for (int i = 0; i < n; i++) { cin >> s; int p, q; if (s[0] == 'D')p = 0; else if (s[0] == 'C')p = 1; else if (s[0] == 'H')p = 2; else p = 3; if (isdigit(s[1]))q = static_cast(s[0] - '0'); else if (s[1] == 'A')q = 1; else if (s[1] == 'T')q = 10; else if (s[1] == 'J')q = 11; else if (s[1] == 'Q')q = 12; else q = 13; v.push_back(make_pair(make_pair(p, q), s)); } sort(v.begin(), v.end()); for (int i = 0; i < n; i++) { if (i)cout << " " << v[i].second; else cout << v[i].second; } cout << endl; return 0; }