n=int(eval(input()))

s=[0]*n

t=[0]*n

for i in range(n):

    a,b=input().split()

    b=int(b)

    s[i]=a

    t[i]=b

x=eval(input())

ans=sum(t)

for i in range(n):

    if s[i]==x:

        print((ans-t[i]))

        exit()

    else:

        ans-=t[i]
n=int(eval(input()))

s=[0]*n

t=[0]*n

for i in range(n):

    s[i],t[i]=input().split()

    t[i]=int(t[i])

print((sum(t[s.index(eval(input()))+1:])))
n = int(eval(input()))
s = [0] * n
t = [0] * n
for i in range(n):
    a, b = input().split()
    b = int(b)
    s[i] = a
    t[i] = b
x = eval(input())
ans = sum(t)
for i in range(n):
    if s[i] == x:
        print((ans - t[i]))
        exit()
    else:
        ans -= t[i]

n = int(eval(input()))
s = [0] * n
t = [0] * n
for i in range(n):
    s[i], t[i] = input().split()
    t[i] = int(t[i])
print((sum(t[s.index(eval(input())) + 1 :])))

-    a, b = input().split() -    b = int(b) -    s[i] = a -    t[i] = b -x = eval(input()) -ans = sum(t) -for i in range(n): -    if s[i] == x: -        print((ans - t[i])) -        exit() -    else: -        ans -= t[i] +    s[i], t[i] = input().split() +    t[i] = int(t[i]) +print((sum(t[s.index(eval(input())) + 1 :])))