def Mileage(a, b):
    if b == 'F':
        return 2*a
    elif b == 'B':
        return int(a + 0.5*a + 0.5)
    elif b == 'Y' and a >= 500:
        return a
    else:
        return 500
s1 = 0
while True:

    
    s = list(input().split())
    if s[0] == '0' or s[0] == '#':
        break
    s1+=Mileage(int(s[2]), s[-1])
print(s1)