#include #include #include typedef std::pair P; int main(){ int n; std::cin >> n; P p[60]; for (int i = 0; i < n; ++i){ std::string str; std::cin >> str; int m, n; m = (str[0] == 'D' ? 0 : str[0] == 'C' ? 1 : str[0] == 'H' ? 2 : str[0] == 'S' ? 3 : -1); n = (str[1] == 'A' ? 1 : str[1] == 'T' ? 10 : str[1] == 'J' ? 11 : str[1] == 'Q' ? 12 : str[1] == 'K' ? 13 : str[1] - '0'); p[i] = P(m * 13 + n, str); } std::sort(p, p + n); std::cout << p[0].second; for (int i = 1; i < n; ++i)std::cout << " " << p[i].second; std::cout << std::endl; return 0; }