_ = int(input()) d = [''] * 14 c = d[:] h = d[:] s = d[:] for i in input().split(): x = int({'A':1, 'T':10, 'J':11, 'Q':12, 'K':13}.get(i[1], i[1])) if 'D' in i: d[x] = i elif 'C' in i: c[x] = i elif 'H' in i: h[x] = i elif 'S' in i: s[x] = i l = d + c + h + s print(*[i for i in l if i])