#include<iostream>
int main()
{
int n , m ;
int color[52] = {0} ;
int number[52] = {0} ;
std::cin >> n ;
for(int i = 0 ; i < n ; i++)
{
char c ;
std::cin >> c >> number[i] ;
if( c == 'S' )
color[i] = 4 ;
else if( c == 'H' )
color[i] = 3 ;
else if( c == 'D' )
color[i] = 2 ;
else if( c == 'C' )
color[i] = 1 ;
}
for(int i = 0 ; i < n ; i++)
for(int j = i + 1 ; j < n ; j++)
if( number[i] < number[j] )
{
int tmp = number[i] ;
number[i] = number[j] ;
number[j] = tmp ;
int ctmp = color[i] ;
color[i] = color[j] ;
color[j] = ctmp ;
}
for(int i = 0 ; i < n ; i++)
for(int j = i + 1 ; j <= i + 3 ; j++)
{
if( number[i] != number[j] )
break ;
else
if( color[i] < color[j] )
{
int tmp = number[i] ;
number[i] = number[j] ;
number[j] = tmp ;
int ctmp = color[i] ;
color[i] = color[j] ;
color[j] = ctmp ;
}
}
std::cin >> m ;
if( color[ m - 1 ] == 4 )
std::cout << "S " ;
else if( color[ m - 1 ] == 3 )
std::cout << "H " ;
else if( color[ m - 1 ] == 2 )
std::cout << "D " ;
else if( color[ m - 1 ] == 1 )
std::cout << "C " ;
std::cout << number[ m - 1 ] << "\n" ;
return 0 ;
}