from collections import Counter 
n=int(input())
a=list(map(int,input().split()))
a=Counter(a)
q=int(input())
for i in range(q):
  b,c=map(int,input().split())
  if a[c]:
    a[c]+=a[b]
  else:a[c]=a[b]
  a[b]=0
  print(sum(a.elements()))
  