from collections import Counter as c

n=int(input())
a=list(map(int,input().split()))
q=int(input())

d=c(a)

for _ in range(q):
  b,c=map(int,input().split())
  num=d.pop(b,0)
  d.setdefault(c,0)
  d[c]+=num
  
  s=0
  for k,v in d.items():
    s+=k*v
  print(s)