array = [0 for i in range(11)]
N = int(input())
A = list(map(int, input().split()))
Q = int(input())

for a in A:
    array[a] += 1
souwa = sum(A)

B = []
C = []
for i in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

for i in range(Q):
    souwa = souwa + (C[i]-B[i])*array[B[i]]
    array[C[i]] += array[B[i]]
    array[B[i]] = 0
    print(souwa)
