N = int(input()) D,C,H,S = [],[],[],[] for card in input().split(): num = card[1] if num == 'A': num = '1' elif num == 'T': num = '10' elif num == 'J': num = '11' elif num == 'Q': num = '12' elif num == 'K': num = '13' if card[0] == 'D': D.append(['D',num]) elif card[0] == 'C': C.append(['C',num]) elif card[0] == 'H': H.append(['H',num]) else: S.append(['S',num]) D.sort() C.sort() H.sort() S.sort() D.extend(C) D.extend(H) D.extend(S) ans = [] print (D) for d in D: suit = d[0] num = d[1] if num == '1': num = 'A' elif num == '10': num = 'T' elif num == '11': num = 'J' elif num == '12': num = 'Q' elif num == '13': num = 'K' ans.append(suit + num) print(' '.join(ans))