N = int(input())
A = list(map(int, input().split()))
Q = int(input())

ans = []

B = [0] * Q
C = [0] * Q
for i in range(Q):
    B[i], C[i] = map(int, input().split())
    A = [C[i] if l == B[i] else l for l in A]
    ans.append(sum(A))

for i in ans:
    print(i)
