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)
#print(d)
for i in range(q):
  ans=0
  for k,v in d.items():
    if k==b[i]:
      removed=d.pop(b[i])
      d[c[i]]+=removed
      break
  #print(d)
  for k,v in d.items():
    #print(ans,k,v)
    ans+=k*v
  print(ans)
  