import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
Q = int(input())
B = []
C = []
for _ in range(Q):
    b,c = map(int, input().split())
    B.append(b)
    C.append(c)

m = max(max(A), max(B), max(C))+1
res = np.arange(m,dtype=int)
newA = np.zeros((m),dtype=int)


for a in A:
    newA[a] += 1

for i in range(Q):
    newA[C[i]] += newA[B[i]]
    newA[B[i]] = 0
    print(np.dot(res,newA))