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

A=[0]*(10**5+1)
for i in range(10**5+1):
  A[i] = a.count(i)

sum_tmp = sum(a)
for i in range(q):
  b = bc[i][0]
  c = bc[i][1]
  A[c] += A[b]
  sum_tmp += (c-b) * A[b]
  A[b] = 0
  
  print(sum_tmp)