S = %w/D C H S/ N = %w/A 2 3 4 5 6 7 8 9 10 J Q K/ D = S.product(N).map {|(suit,num)| suit + num } I = 52.times.each_with_object({}) do |i,o| o[D[i]] = i end n = gets.to_i puts gets.chomp.split.sort {|a,b| I[a] <=> I[b]}.join(' ')