n = int(input())
la = list(map(int, input().split()))
q = int(input())
ls = sum(la)
lc = []
lc_cnt = []
for i in range(q):
  b, c = map(int, input().split())
  cnt = la.count(b)
  if lc.count(b) > 0:
    j = 0
    for k in lc:
      cnt += lc_cnt[j] if k == b else 0
      j += 1
  ls += (c-b)*cnt
  
  lc.append(c)
  lc_cnt.append(cnt)
  print(ls)