N = int(input())
A = list(map(int, input().split()))
Q = int(input())
A = sorted(A)
for i in range(Q):
  B, C = map(int,input().split())
  flag = False
  for j in range(N):
    if A[j]==B:
      A[j]=C
      flag = True
    elif flag:
      break

  print(sum(A))
