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

for i in range(q):
  b, c = map(int, input().split())
  a_tmp2 = [c if j == b else j for j in a_tmp]
  ans = sum(a_tmp2)
  a_tmp = a_tmp2
  print(ans)
  