import sys
import numpy as np

readline = sys.stdin.readline
read = sys.stdin.read

n = int(readline())
a = np.array(readline().split(), dtype=np.int64)
q = int(readline())
bc = np.array(read().split(), dtype=np.int64)
ans = np.sum(a)
for i in range(q):
    x = a==bc[2*i]
    a[x] = bc[2*i+1]
    ans += np.count_nonzero(x) * (bc[2*i+1] - bc[2*i])
    print(ans)
