import numpy as np

x = np.zeros(100_001, dtype=int)
v = np.arange(100_001)

n = int(input())
for a in map(int, input().split()):
  x[a] += 1
q = int(input())
for _ in range(q):
  b, c = map(int, input().split())
  x[c] += x[b]
  x[b] = 0
  print(x @ v)