import numpy as np

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B, C = np.zeros(Q, dtype=np.int32), np.zeros(Q, dtype=np.int32)
for i in range(Q):
    [b, c] = list(map(int, input().split()))
    B[i], C[i] = b, c


for i in range(Q):
    A = np.where(A==B[i], C[i], A)
    print(np.sum(A))
