N = int(input())
A = list(map(int, input().split()))
lenA = len(A)
Q = int(input())
B = []
C = []
for i in range(Q):
  b, c = map(int, input().split())
  B.append(b)
  C.append(c)
cnt = 0

for i in range(Q):
  for j in range(lenA):
    if A[j] == B[i]:
      A[j] = C[i]
  for j in range(lenA):
    cnt += A[j]
  print(cnt)
  cnt = 0
