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

ans = 0
for _ in range(q):
    b, c = map(int, input().split())
    if b in A:
        A = [c if a==b else a for a in A]
        ans = sum(A)
    print(ans)