import std.stdio, std.conv, std.math, std.string, std.range, std.array, std.algorithm; void main() { readln(); auto buf = readln().strip().split().map!(to!string)().array(); int[char] sp = ['D' : 0, 'C' : 1, 'H' : 2, 'S' : 3]; int[char] nm = ['A' : 1, 'T' : 10, 'J' : 11, 'Q' : 12, 'K' : 13]; foreach(i; 2..10) { nm[i.to!string[0]] = i; } buf.sort!((a, b) => (sp[a[0]] != sp[b[0]]) ? (sp[a[0]] < sp[b[0]]) : (nm[a[1]] < nm[b[1]]) )(); buf.join(" ").writeln(); }