import numpy as np
N = int(input())
As = np.array(input().split()).astype(np.int64)

Q = int(input())

for q in range(Q):
  B, C = map(int, input().split())
  As[np.where(As==B)] = C
  print(As.sum())