n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = []
ans = []
for i in range(q):
  bc.append(list(map(int, input().split())))
for i in range(q):
  b = bc[i][0]
  c = bc[i][1]
  for j in range(n):
    if a[j] == b:
      a[j] = c
  ans.append(sum(a))
for i in range(q):
  print(ans[i])