import numpy as np
from collections import Counter as C

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]

d=C(a)
d2={}
for k,v in d.items():
  d2[k]=k*v

#print(d)
for i in range(q):
  ans=0
  #print(d2)
  for k,v in d.items():
    if k==b[i]:
      #print("b[i]",b[i])
      removed=d.pop(b[i])
      no=d2.pop(b[i])
      d[c[i]]+=removed
      d2[c[i]]=c[i]*d[c[i]]
      break
  print(sum(d2.values()))
  
