n = int(input())
m = input().split()

k = {"A":1, "T":10, "J":11, "Q":12, "K":13}
r = {1: "A", 10: "T", 11: "J", 12: "Q", 13: "K"}

t = []
for i in range(n):
    a, b = list(m[i])
    if a == "D":
        a = 0
        if b in k:
            b = k[b]
    elif a == "C":
        a = 1
        if b in k:
            b = k[b]
    elif a == "H":
        a = 2
        if b in k:
            b = k[b]
    elif a == "S":
        a = 3
        if b in k:
            b = k[b]
    b = int(b)
    t.append([a, b])

t.sort()

for k, v in t:
    if k == 0:
        k = "D"
        if v in r:
            v = r[v]
            print(k + v, end=" ")
        else:
            print(k + str(v), end=" ")
    elif k == 1:
        k = "C"
        if v in r:
            v = r[v]
            print(k + v, end=" ")
        else:
            print(k + str(v), end=" ")
    elif k == 2:
        k = "H"
        if v in r:
            v = r[v]
            print(k + v, end=" ")
        else:
            print(k + str(v), end=" ")
    elif k == 3:
        k = "S"
        if v in r:
            v = r[v]
            print(k + v, end=" ")
        else:
            print(k + str(v), end=" ")
print()