import numpy as np
n=int(input())
a = list(input().split())
a = [int(i) for i in a]
q=int(input())
bc=[list(map(int,input().split())) for i in range(q)]
bc=np.array(bc).T
b=bc[0]
c=bc[1]

ans=sum(a)
for i in range(q):
  #print(a)
  count=a.count(b[i])
  ans+=(c[i]-b[i])*count
  print(ans)
  a=[c[i] if b[i]==a[ii] else a[ii] for ii in range(n)]
  
  