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

arr_B=[] 
arr_C=[] 

for i in range(Q):
  B, C = list(map(int, input().split()))
  arr_B.append(B)
  arr_C.append(C)

for i in range(Q):
  for j in range(N):
    if arr_B[i] == A[j]:
      A[j] = arr_C[i]
  print(sum(A))