n = int(eval(input()))

res = 0

for i in range(n):

  x, u = input().split()

  x = float(x)

  if u == 'JPY':

    res += x

  else:

    res += (380000 * x)

print(res)
res=0

for i in range(int(eval(input()))):

  x,u=input().split()

  x=float(x)

  res+=x if u>'C'else 380000*x

print(res)
n = int(eval(input()))
res = 0
for i in range(n):
    x, u = input().split()
    x = float(x)
    if u == "JPY":
        res += x
    else:
        res += 380000 * x
print(res)

res = 0
for i in range(int(eval(input()))):
    x, u = input().split()
    x = float(x)
    res += x if u > "C" else 380000 * x
print(res)

-n = int(eval(input())) -for i in range(n): +for i in range(int(eval(input()))): -    if u == "JPY": -        res += x -    else: -        res += 380000 * x +    res += x if u > "C" else 380000 * x