N = int(input())
As = list(map(int, input().split()))
Q = int(input())

sumAs = sum(As)

for _ in range(Q):
  b, c = map(int, input().split())
  for i in range(len(As)):
    if As[i] == b:
      As[i] = c
      sumAs = sumAs - b + c
  print(sumAs)
  
