# import sys; input = sys.stdin.buffer.readline # sys.setrecursionlimit(10**7) from collections import defaultdict con = 10 ** 9 + 7; INF = float("inf") def getlist(): return list(map(int, input().split())) #処理内容 def main(): N = int(input()) L = list(input().split()) L2 = [] for i in L: val = [None, None] if i[0] == "D": val[0] = 0 elif i[0] == "C": val[0] = 1 elif i[0] == "H": val[0] = 2 else: val[0] = 3 if i[1] == "A": val[1] = 1 elif i[1] == "T": val[1] = 10 elif i[1] == "J": val[1] = 11 elif i[1] == "Q": val[1] = 12 elif i[1] == "K": val[1] = 13 else: val[1] = int(i[1]) L2.append(val) L2.sort() # print(L2) ans = [] for mark, val in L2: s = "" if mark == 0: s += "D" elif mark == 1: s += "C" elif mark == 2: s += "H" else: s += "S" if val == 1: s += "A" elif val == 10: s += "T" elif val == 11: s += "J" elif val == 12: s += "Q" elif val == 13: s += "K" else: s += str(val) ans.append(s) print(*ans) if __name__ == '__main__': main()