N = int(input())
A = list(map(int, input().split()))
Q = int(input())
ans = []
for i in range(Q):
  B, C = map(int, input().split())
  for j in range(len(A)):
    if A[j] == B:
      A[j] = C
  ans.append(sum(A))

for k in ans:
  print(k)