import numpy as np

n = int(input())

a = list(map(int, input().split()))

a_array = np.zeros((100001), dtype = np.int)
a_array = a_array.reshape((1, 100001))
a_val = np.arange(100001)
a_val = a_val.reshape((1, 100001))
a_val = a_val.transpose()

for i in range(len(a)):
  a_array[0, a[i]] += 1

q = int(input())

for i in range(q):
  b, c = map(int, input().split())
  a_array[0, c] += a_array[0 ,b]
  a_array[0, b] = 0
  print(np.dot(a_array, a_val)[0,0])