input();print" ".join(sorted(raw_input().split(),key=lambda(x,y):("DCHS".index(x),"A23456789TJQK".index(y))))