import numpy as np

N = int(input())
As = list(map(int, input().split()))
Q = int(input())
BCs = [list(map(int, input().split())) for _ in range(Q)]

#rint(BCs)

ansArray = np.zeros(10**5 + 1, dtype = int)
indexArray = np.array(range(10**5+1))

for A in As:
    ansArray[A] += 1

#print(ansArray)
#print(indexArray)

for BC in BCs:
    B = BC[0]
    C = BC[1]

    tmp = ansArray[B]
    ansArray[B] = 0
    ansArray[C] += tmp

    print(np.dot(ansArray, indexArray))

