n = int(input())
a = list(map(int,input().split()))
q = int(input())
xy = [map(int, input().split()) for _ in range(q)]
x, y = [list(i) for i in zip(*xy)]
for j in range(q):
  a = [y[j] if i==x[j] else i for i in a]
  print(sum(a))