import sys
input = sys.stdin.readline

import numpy as np

n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = [list(map(int,input().split())) for i in range(q)]

l = np.array([0] * 100000)
m = np.array(list(range(1,100001)))

for i in range(n):
  l[a[i]-1] += 1
  
for j in range(q):
  l[b[j][1]-1] += l[b[j][0]-1]
  l[b[j][0]-1] = 0
  print(sum(l*m))
