n = int(input())
la = list(map(int, input().split()))
q = int(input())
for i in range(q):
  li = la
  b, c = map(int, input().split())
  for j in range(len(la)):
    if li[j] == b:
      li[j] = c
  print(sum(li))