def suit_score(c) %w[D C H S].index(c) end def letter_score(c) %w[A 2 3 4 5 6 7 8 9 T J Q K].index(c) end n = gets.to_i cards = gets.split puts cards.sort_by { |s| [suit_score(s[0]), letter_score(s[1])] }.join(" ")