program acsl;

(*matija bucic

  xv. gimnazija

  contest #2

  intermediate division*)

 

var di,cl,he,sp:array[1..6] of longint;

    i,j,tr,ld,lc,lh,ls,br:longint;

    d,c,h,s,tru:string;

function card(ch:string[1]):integer;

begin;

if ch='A' then card:=1;

if ch='K' then card:=2;

if ch='Q' then card:=3;

if ch='J' then card:=4;

if ch='T' then card:=5;

if ch='N' then card:=6;

end;

begin

for j:=1 to 5 do

begin;

readln(tru);

readln(d);

readln(c);

readln(s);

readln(h);

if tru='D' then tr:=1;

if tru='C' then tr:=2;

if tru='S' then tr:=3;

if tru='H' then tr:=4;

ld:=length(d);

lc:=length(c);

ls:=length(s);

lh:=length(h);

for i:=1 to ld do

inc(di[card(d[i])]);

for i:=1 to lc do

inc(cl[card(c[i])]);

for i:=1 to ls do

inc(sp[card(s[i])]);

for i:=1 to lh do

inc(he[card(h[i])]);

if (di[4]>=2) and (sp[3]>=2) then br:=br+34;

if (di[4]>=1) and (sp[3]>=1) then br:=br+4;

if ((di[1]>=1) and (cl[1]>=1)) and ((sp[1]>=1) and (he[1]>=1)) then br:=br+10;

if ((di[3]>=1) and (cl[3]>=1)) and ((sp[3]>=1) and (he[3]>=1)) then br:=br+6;

if ((di[2]>=1) and (cl[2]>=1)) and ((sp[2]>=1) and (he[2]>=1)) then br:=br+8;

if ((di[4]>=1) and (cl[4]>=1)) and ((sp[4]>=1) and (he[4]>=1)) then br:=br+4;

if ((di[1]>=2) and (cl[1]>=2)) and ((sp[1]>=2) and (he[1]>=2)) then br:=br+110;

if ((di[3]>=2) and (cl[3]>=2)) and ((sp[3]>=2) and (he[3]>=2)) then br:=br+66;

if ((di[2]>=2) and (cl[2]>=2)) and ((sp[2]>=2) and (he[2]>=2)) then br:=br+88;

if ((di[4]>=2) and (cl[4]>=2)) and ((sp[4]>=2) and (he[4]>=2)) then br:=br+44;

if (tr=1) then

begin;

      if (((di[1]>=2) and (di[2]>=2)) and (di[3]>=2)) and ((di[4]>=2) and (di[5]>=2)) then br:=br+150;

      if (((sp[1]>=1) and (sp[2]>=1)) and (sp[3]>=1)) and ((sp[4]>=1) and (sp[5]>=1)) then br:=br+50;

      if (((cl[1]>=1) and (cl[2]>=1)) and (cl[3]>=1)) and ((cl[4]>=1) and (cl[5]>=1)) then br:=br+50;

      if (((he[1]>=1) and (he[2]>=1)) and (he[3]>=1)) and ((he[4]>=1) and (he[5]>=1)) then br:=br+50;

      if (((sp[1]>=2) and (sp[2]>=2)) and (sp[3]>=2)) and ((sp[4]>=2) and (sp[5]>=2)) then br:=br+50;

      if (((cl[1]>=2) and (cl[2]>=2)) and (cl[3]>=2)) and ((cl[4]>=2) and (cl[5]>=2)) then br:=br+50;

      if (((he[1]>=2) and (he[2]>=2)) and (he[3]>=2)) and ((he[4]>=2) and (he[5]>=2)) then br:=br+50;

end;

if (tr=2) then

begin;

      if (((cl[1]>=2) and (cl[2]>=2)) and (cl[3]>=2)) and ((cl[4]>=2) and (cl[5]>=2)) then br:=br+150;

      if (((sp[1]>=1) and (sp[2]>=1)) and (sp[3]>=1)) and ((sp[4]>=1) and (sp[5]>=1)) then br:=br+50;

      if (((di[1]>=1) and (di[2]>=1)) and (di[3]>=1)) and ((di[4]>=1) and (di[5]>=1)) then br:=br+50;

      if (((he[1]>=1) and (he[2]>=1)) and (he[3]>=1)) and ((he[4]>=1) and (he[5]>=1)) then br:=br+50;

      if (((sp[1]>=2) and (sp[2]>=2)) and (sp[3]>=2)) and ((sp[4]>=2) and (sp[5]>=2)) then br:=br+50;

      if (((di[1]>=2) and (di[2]>=2)) and (di[3]>=2)) and ((di[4]>=2) and (di[5]>=2)) then br:=br+50;

      if (((he[1]>=2) and (he[2]>=2)) and (he[3]>=2)) and ((he[4]>=2) and (he[5]>=2)) then br:=br+50;

end;

if (tr=3) then

begin;

      if (((sp[1]>=2) and (sp[2]>=2)) and (sp[3]>=2)) and ((sp[4]>=2) and (sp[5]>=2)) then br:=br+150;

      if (((di[1]>=1) and (di[2]>=1)) and (di[3]>=1)) and ((di[4]>=1) and (di[5]>=1)) then br:=br+50;

      if (((cl[1]>=1) and (cl[2]>=1)) and (cl[3]>=1)) and ((cl[4]>=1) and (cl[5]>=1)) then br:=br+50;

      if (((he[1]>=1) and (he[2]>=1)) and (he[3]>=1)) and ((he[4]>=1) and (he[5]>=1)) then br:=br+50;

      if (((di[1]>=2) and (di[2]>=2)) and (di[3]>=2)) and ((di[4]>=2) and (di[5]>=2)) then br:=br+50;

      if (((cl[1]>=2) and (cl[2]>=2)) and (cl[3]>=2)) and ((cl[4]>=2) and (cl[5]>=2)) then br:=br+50;

      if (((he[1]>=2) and (he[2]>=2)) and (he[3]>=2)) and ((he[4]>=2) and (he[5]>=2)) then br:=br+50;

end;

if (tr=4) then

begin;

      if (((he[1]>=2) and (he[2]>=2)) and (he[3]>=2)) and ((he[4]>=2) and (he[5]>=2)) then br:=br+150;

      if (((sp[1]>=1) and (sp[2]>=1)) and (sp[3]>=1)) and ((sp[4]>=1) and (sp[5]>=1)) then br:=br+50;

      if (((cl[1]>=1) and (cl[2]>=1)) and (cl[3]>=1)) and ((cl[4]>=1) and (cl[5]>=1)) then br:=br+50;

      if (((di[1]>=1) and (di[2]>=1)) and (di[3]>=1)) and ((di[4]>=1) and (di[5]>=1)) then br:=br+50;

      if (((sp[1]>=2) and (sp[2]>=2)) and (sp[3]>=2)) and ((sp[4]>=2) and (sp[5]>=2)) then br:=br+50;

      if (((cl[1]>=2) and (cl[2]>=2)) and (cl[3]>=2)) and ((cl[4]>=2) and (cl[5]>=2)) then br:=br+50;

      if (((di[1]>=2) and (di[2]>=2)) and (di[3]>=2)) and ((di[4]>=2) and (di[5]>=2)) then br:=br+50;

end;

writeln(br);

readln;

br:=0;

for i:=1 to 6 do

begin;

di[i]:=0;

sp[i]:=0;

cl[i]:=0;

he[i]:=0;

end;

end;

end.