n = int(input())
a = list(map(str, input().split()))
q = int(input())
b = [0] * q
c = [0] * q
for i in range(q):
    b[i], c[i] = map(str, input().split())

tmp = ','.join(a)

for i in range(q):
    tmp = tmp.replace(b[i], c[i])
    ans = list(tmp.split(','))
    ans2 = 0
    for j in ans:
        ans2 += int(j)
    print(ans2)