N = int(input())
A = list(map(int, input().split()))
Q = int(input())
L = [[int(j) for j in input().split()] for i in range(Q)]

newList = A
total = sum(newList)
for i in L:
  if i[0] in newList:
    n = newList.count(i[0])
    diff = i[1] - i[0]
    total = total + (diff * n)
    print(total)
    newList = [j for j in newList if j != i[0]]
    newList.extend([i[1]] * n)
  else:
    print(total)