//Jerry Shen
//Freehold High School
//School Code: 9001
//Intermediate Division
//Contest II
//C++ Language
//Advisor: J. Gill
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
void set(string str)
{
string hand=str,
trump="", d[16],c[16],s[16],h[16];
//cin>>hand;
//determine trump
trump =
hand.substr(0,1);
hand = hand.substr(2,hand.size()-2);
//sort cards
[diamonds]
int x=0, i=0;
do
{if(hand.substr(x,1) != "," ){d[x]=hand.substr(x,1);x++;} else
{i=1;}}
while (i==0);
hand=
hand.substr(x+1,hand.size()-x+1);i=0;x=0;
do
{if(hand.substr(x,1) != "," ){c[x]=hand.substr(x,1);x++;} else
{i=1;}}
while (i==0);
hand=
hand.substr(x+1,hand.size()-x+1);i=0;x=0;
do
{if(hand.substr(x,1) != "," ){s[x]=hand.substr(x,1);x++;} else
{i=1;}}
while (i==0);
hand=
hand.substr(x+1,hand.size()-x+1);i=0;x=0;
for(x=0;x<=hand.size()-1;x++){h[x]=hand.substr(x,1);}
///
///
//point
calculations
///
///
int score=0,
calc=0;
//Case 1
if(trump=="D")
{ x=0;
do{if(d[x]=="A" || d[x]=="K" || d[x]=="Q"
|| d[x]=="J" ||
d[x]=="T"){calc++;}x++;}while(d[x]!="");
if(calc>=10)
{score+=150;x=0;calc=0;}
}
if(trump=="C")
{ x=0;
do{if(c[x]=="A" || c[x]=="K" || c[x]=="Q"
|| c[x]=="J" ||
c[x]=="T"){calc++;}x++;}while(c[x]!="");
if(calc>=10) {score+=150;x=0;calc=0;}
}
if(trump=="S")
{ x=0;
do{if(s[x]=="A" || s[x]=="K" || s[x]=="Q"
|| s[x]=="J" ||
s[x]=="T"){calc++;}x++;}while(s[x]!="");
if(calc>=10)
{score+=150;x=0;calc=0;}
}
if(trump=="H")
{ x=0;
do{if(h[x]=="A" || h[x]=="K" || h[x]=="Q"
|| h[x]=="J" ||
h[x]=="T"){calc++;}x++;}while(h[x]!="");
if(calc>=10)
{score+=150;x=0;calc=0;}
}
//Case 2
calc=0;
for(x=0;x<=15;x++){if(d[x]=="J") {calc++;}}
for(x=0;x<=15;x++){if(s[x]=="Q") {calc++;}}
if(calc==8){score+=30;}
//case 3
calc=0;
for(x=0;x<=15;x++){if(d[x]=="A") {calc++;break;}}
for(x=0;x<=15;x++){if(c[x]=="A") {calc++;break;}}
for(x=0;x<=15;x++){if(s[x]=="A") {calc++;break;}}
for(x=0;x<=15;x++){if(h[x]=="A") {calc++;break;}}
if(calc==4){score+=10;}
//case 4
calc=0;
for(x=0;x<=15;x++){if(d[x]=="K") {calc++;break;}}
for(x=0;x<=15;x++){if(c[x]=="K") {calc++;break;}}
for(x=0;x<=15;x++){if(s[x]=="K") {calc++;break;}}
for(x=0;x<=15;x++){if(h[x]=="K") {calc++;break;}}
if(calc==4){score+=8;}
//case 5
calc=0;
for(x=0;x<=15;x++){if(d[x]=="A") {calc++;}}
for(x=0;x<=15;x++){if(c[x]=="A") {calc++;}}
for(x=0;x<=15;x++){if(s[x]=="A") {calc++;}}
for(x=0;x<=15;x++){if(h[x]=="A") {calc++;}}
if(calc==8){score+=100;}
//case 6
calc=0;
for(x=0;x<=15;x++){if(d[x]=="K") {calc++;}}
for(x=0;x<=15;x++){if(c[x]=="K") {calc++;}}
for(x=0;x<=15;x++){if(s[x]=="K") {calc++;}}
for(x=0;x<=15;x++){if(h[x]=="K") {calc++;}}
if(calc==8){score+=80;}
//case 7
if(trump!="D"){
for(x=0;x<=15;x++){
if(d[x]=="A"){
for(x=0;x<=15;x++){
if(d[x]=="K"){
for(x=0;x<=15;x++){
if(d[x]=="Q"){
for(x=0;x<=15;x++){
if(d[x]=="J"){
for(x=0;x<=15;x++){
if(d[x]=="T"){score+=50;}}}}}}}}}}}
if(trump!="C"){for(x=0;x<=15;x++){if(c[x]=="A"){for(x=0;x<=15;x++){if(c[x]=="K"){for(x=0;x<=15;x++){if(c[x]=="Q"){for(x=0;x<=15;x++){if(c[x]=="J"){for(x=0;x<=15;x++){if(c[x]=="T"){score+=50;}}}}}}}}}}}
if(trump!="S"){for(x=0;x<=15;x++){if(s[x]=="A"){for(x=0;x<=15;x++){if(s[x]=="K"){for(x=0;x<=15;x++){if(s[x]=="Q"){for(x=0;x<=15;x++){if(s[x]=="J"){for(x=0;x<=15;x++){if(s[x]=="T"){score+=50;}}}}}}}}}}}
if(trump!="H"){for(x=0;x<=15;x++){if(h[x]=="A"){for(x=0;x<=15;x++){if(h[x]=="K"){for(x=0;x<=15;x++){if(h[x]=="Q"){for(x=0;x<=15;x++){if(h[x]=="J"){for(x=0;x<=15;x++){if(h[x]=="T"){score+=50;}}}}}}}}}}}
//case 8
calc=0;
for(x=0;x<=15;x++){if(d[x]=="J") {calc++;break;}}
for(x=0;x<=15;x++){if(s[x]=="Q") {calc++;break;}}
if(calc==2){score+=4;}
//case 9
calc=0;
for(x=0;x<=15;x++){if(d[x]=="Q") {calc++;break;}}
for(x=0;x<=15;x++){if(c[x]=="Q") {calc++;break;}}
for(x=0;x<=15;x++){if(s[x]=="Q") {calc++;break;}}
for(x=0;x<=15;x++){if(h[x]=="Q") {calc++;break;}}
if(calc==4){score+=6;}
//case 10
calc=0;
for(x=0;x<=15;x++){if(d[x]=="J") {calc++;break;}}
for(x=0;x<=15;x++){if(c[x]=="J") {calc++;break;}}
for(x=0;x<=15;x++){if(s[x]=="J") {calc++;break;}}
for(x=0;x<=15;x++){if(h[x]=="J") {calc++;break;}}
if(calc==4){score+=4;}
//case 11
calc=0;
for(x=0;x<=15;x++){if(d[x]=="Q") {calc++;}}
for(x=0;x<=15;x++){if(c[x]=="Q") {calc++;}}
for(x=0;x<=15;x++){if(s[x]=="Q")
{calc++;}}
for(x=0;x<=15;x++){if(h[x]=="Q") {calc++;}}
if(calc==8){score+=60;}
//case 12
calc=0;
for(x=0;x<=15;x++){if(d[x]=="J") {calc++;}}
for(x=0;x<=15;x++){if(c[x]=="J") {calc++;}}
for(x=0;x<=15;x++){if(s[x]=="J") {calc++;}}
for(x=0;x<=15;x++){if(h[x]=="J") {calc++;}}
if(calc==8){score+=40;}
cout<<score<<"\n";
}
int main ()
{
string str;
for(int a=1; a<=5; a++)
{
cin>>str;
set(str);
}
cin>>str;
}