import numpy as np

N = int(input())
a = np.array(list(map(int, input().split())))
Q = int(input())
bc = [list(map(int, input().split())) for _ in range(Q)]

for i in range(Q):
    b, c = bc[i]
    a[a == b] = c
    print(np.sum(a))