n = int(input())
la = list(map(int, input().split()))
q = int(input())
sa = sum(la)
lc = []
for i in range(q):
  b, c = map(int, input().split())
  cnt1 = la.count(b)
  cnt2 = lc.count(b)
  sa += (c-b)*(cnt1+cnt2)  
  print(sa)
  
  lc += [c]*cnt1