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

for i in range(Q):
  while B[i] in A:
    check = A.index(B[i])
    A[check] = C[i]
  print(sum(A))