N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for _ in range(Q):
  l = list(map(int, input().split()))
  B.append(l[0])
  C.append(l[1])

for i in range(Q):
  for j in range(len(A)):
    if A[j] == B[i]:
      A[j] = C[i]
  print(sum(A))