n = int(input())
a = list(map(int, input().split()))
q = int(input())
ans = 0
b = [0] * q
c = [0] * q

for i in range(n):
    ans += a[i]
    
for i in range(q):
    b, c = map(int, input().split())
    for j in range(n):
        if a[j] == b:
            a[j] = c
            ans  += c-b
    print(ans)