n = int(input())
A = list(map(int, input().split()))
q = int(input())

ans = 0
for i in A:
    ans += i

for i in range(q):
    b, c = map(int, input().split())
    d = c - b
    cnt = 0
    for j in range(len(A)):
        if A[j] == b:
            A[j] = c
            cnt += 1
    ans += d*cnt
    print(ans)
