import numpy as np
n = int(input())
a =np.array([int(x) for x in input().split()])
q = int(input())
bc = [map(int, input().split()) for _ in range(q)]
b, c = [list(i) for i in zip(*bc)]

ans = np.sum(a)
for i in range(q):
    if np.count_nonzero(a == b[i]) > 0:
        a = np.where(a == b[i], c[i],a)
        ans += np.count_nonzero(a == b[i])*(c[i]-b[i])
    print(ans)