N = int(input()) D,C,H,S = [],[],[],[] for card in input().split(): num = card[1] if num == 'A': num = '1' elif num == 'T': num = '90' elif num == 'J': num = '91' elif num == 'Q': num = '92' elif num == 'K': num = '93' 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 = [] for d in D: suit = d[0] num = d[1] if num == '1': num = 'A' elif num == '90': num = 'T' elif num == '91': num = 'J' elif num == '92': num = 'Q' elif num == '93': num = 'K' ans.append(suit + num) print(' '.join(ans))