N = int(input())
A = list(map(int,input().split()))
Q = int(input())

for i in range(Q):
  B_C = list(map(int,input().split()))
  for j, item in enumerate(A):
    if item == B_C[0]:
      A[j] = B_C[1]
  print(sum(A))