from collections import Counter
n=int(input())
a=list(map(int,input().split()))
suma=sum(a)
dica=Counter(a)
q=int(input())
b=[]
c=[]
for i in range(q):
  b_,c_=map(int,input().split())
  b.append(b_)
  c.append(c_)

i=0
j=0

while i<=(q-1):
  num=dica[b[i]]
  new_sum=suma-b[i]*num+c[i]*num
  print(new_sum)
  
  suma=new_sum
  try:
    dica[c[i]]+=num
  except:
    dica[c[i]]=num
  i+=1
