#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define REP(i,n) for(long (i)=0;(i)<(n);(i)++) #define FOR(i,a,b) for(long (i)=(a);(i)<(b);(i)++) #define RREP(i,a) for(long (i)=(a)-1;(i)>=0;(i)--) #define FORR(i,a,b) for(long (i)=(a)-1;(i)>=(b);(i)--) #define MOD 1000000007 #define PI acos(-1.0) #define DEBUG(C) cout< #define PLL pair #define ALL(a) (a).begin(),(a).end() #define SORT(a) sort((a).begin(),(a).end()) #define RSORT(a) sort((a).begin(),(a).end(),greater()) #define MP(a,b) make_pair(a,b) #define FORE(a,b) for(auto &&a:b) typedef long long LL; typedef unsigned long long ULL; using namespace std; char c[]={'D','C','H','S'}; bool check(string a,string b){ string s[]={a,b}; int n[2]; REP(i,2){ if(s[i][1]=='A')n[i]=1; else if(s[i][1]=='T') n[i]=10; else if(s[i][1]=='J') n[i]=11; else if(s[i][1]=='Q') n[i]=12; else if(s[i][1]=='K') n[i]=13; else n[i]=s[i][1]-'0'; } map mp; REP(i,4) mp[c[i]]=i; if(mp[a[0]]mp[b[0]]) return false; if(n[0]>N; vector m(N); REP(i,N) cin>>m[i]; REP(i,N)FORR(j,N,i+1){ if(check(m[j],m[j-1])) swap(m[j],m[j-1]); } REP(i,N) cout<