import numpy as np
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []

X = np.array([0]*(10**5))
Y = np.array([i  for i in range(1, (10**5)+1)])

for j in range(N):
    X[A[j]-1] += 1

for i in range(Q):
    b, c = map(int, input().split())
    a = X[b-1]
    X[b-1] = 0
    X[c-1] += a
    print(X@Y)