n=int(input())
a=list(map(int,input().split()))
s=sum(a)
l=[0]*(10**5+1)
for i in a:
  l[i]+=1
q=int(input())
for i in range(q):
  b,c=map(int,input().split())
  x=l[b]
  l[b]=0
  s=s-b*x+c*x
  print(s)
  l[c]+=x