N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B, C, S = [], [], []
for j in range(Q):
  b, c = map(int, input().split())
  B.append(b)
  C.append(c)

for i in range(Q):
  A = [C[i] if a == B[i] else a for a in A]
  S.append(sum(A))

for s in S:
  print(s)