N = int(input())
A = [int(i) for i in input().split()]
Q = int(input())
BC = [list(map(int,input().split())) for _ in range(Q)]
numA = []
for i in range(1, 10**5+1):
  numA.append(A.count(i))
ans = sum(A)
for l in BC:
  ans = ans + ((l[1] - l[0]) * numA[l[0]-1])
  print(ans)
  numA[l[1]-1] = numA[l[0]-1] + numA[l[1]-1]
  numA[l[0]-1] = 0

