N = int(input()) C = input().split() D = {} lst = [] for c in C: a = "" if c[0] == "D": a += "A" elif c[0] == "C": a += "B" elif c[0] == "H": a += "C" else: a += "D" if c[1] == "T": a += "10" elif c[1] == "J": a += "11" elif c[1] == "Q": a += "12" elif c[1] == "K": a += "13" elif c[1] == "A": a += "01" else: a += "0" + c[1] D[a] = c lst.append(a) lst.sort() ans = [] for a in lst: ans.append(D[a]) print(*ans)