N = int(input())
A = [0] * N
tempA = list(map(int,input().split()))
for i in range(N):
  A[tempA[i]-1] = A[tempA[i]-1]+1

print(A)
Q = int(input())
for i in range(Q):
  S=0
  B,C = map(int, input().split())
  A[C-1] = A[C-1]+A[B-1]
  A[B-1] = 0
  for j in range(N):
    S = S+((j+1)*A[j])
  print(S)