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

counter=[0]*(10**5+1)
for i in a:
  counter[i]+=1
  
for i in range(q):
  new_sum=suma-b[i]*counter[b[i]]+c[i]*counter[b[i]]
  suma=new_sum
  counter[c[i]]+=1
  counter[b[i]]=0
  print(new_sum)