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