import numpy as np
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
bc = [tuple(map(int, input().split())) for i in range(Q)]
A = np.asarray(A)
for b, c in bc:
    A = np.where(A == b, c, A)
    print(sum(A))
