n = int(input())
a = list(map(int,input().split()))
q = int(input())
b = [0] * q
c = [0] * q

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