#include using namespace std; #define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define rep(i,n) repl(i,0,n) #define mp(a,b) make_pair((a),(b)) #define pb(a) push_back((a)) #define all(x) (x).begin(),(x).end() #define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x)) #define fi first #define se second #define dbg(x) cout<<#x" = "<<((x))< ostream& operator<<(ostream& o, const pair &p){o<<"("< ostream& operator<<(ostream& o, const vector &v){o<<"[";for(T t:v){o<>n; vector> vec; map m ={{'D', 0}, {'C', 20}, {'H', 40}, {'S', 60}, {'A', 1}, {'T', 10}, {'J', 11}, {'Q', 12}, {'K', 13}}; repl(i,1,10) m[i+'0'] = i; rep(i,n){ string str; cin>>str; int x = 0; for(auto c : str) x += m[c]; vec.pb(mp(x,str)); } sort(all(vec)); rep(i,n) cout << vec[i].se << " \n"[i==n-1]; return 0; }