N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for _ in range(Q):
  l = map(int, input().split())
  B.append(l[0])
  C.append(l[1])

for i in range(Q):
  for a in A:
    if a == B[i]:
      a = C[i]
  print(sum(A))