#include<stdio.h>
#include<string.h>
int main()
{
char s1[20],s2[20],classcode;
int miles,count=0,sum=0;
int a[20];
while(1)
{
scanf("%s",s1);
if(strcmp(s1,"0")==0)
{
a[count++]=sum;
sum=0;
continue;
}
else if(strcmp(s1,"#")==0)
break;
scanf("%s",s2);
scanf("%d",&miles);
getchar();
scanf("%c",&classcode);
switch(classcode)
{
case 'F':sum+=2*miles;break;
case 'B':sum+=miles+(int)miles/2;break;
case 'Y':
if(miles>=500)
sum+=miles;
else
sum+=500;
break;
}
}
for(miles=0;miles<count;miles++)
printf("%d\n",a[miles]);
return 0;
}