n=int(input())
l=[int(i) for i in input().split()]
s=sum(l)
d={}
for i in range(n):
  if(l[i] in d):
    d[i]+=1
  else:
    d[i]=1
q=int(input())
for w in range(q):
  b,c=(int(i) for i in input().split())
  if(b in d):
    s-=((d[b]*b)+(d[b]*c))
    d[c]=d[b]
    d[b]=0
  print(s)