#include using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) #define REP(i,a,b) for(int i=(a);i<(b);i++) #define pb push_back #define all(v) (v).begin(),(v).end() typedef vectorvi; typedef pairp; int main(){ int N; cin>>N; vector

vec(N); rep(i,N){ string s;cin>>s; int a,b; if(s[0]=='D')a=0; else if(s[0]=='C')a=1; else if(s[0]=='H')a=2; else a=3; if(isdigit(s[1]))b=s[1]-'0'; else if(s[1]=='J')b=11; else if(s[1]=='Q')b=12; else if(s[1]=='K')b=13; else b=1; b--; vec[i].first=a*13+b; vec[i].second=s; } sort(all(vec)); rep(i,N){ if(i)cout<<" "; cout<