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

for j in range(q):
    for k in range(n):
        if a[k] == b[j]:
            a[k] = c[j]
    print(sum(a))