from collections import Counter

def resolve():
  N = int(input())
  countA = Counter([int(x) for x in input().split(" ")])
  Q = int(input())

  sum_A = 0
  for a in countA.items():
    sum_A += a[0]*a[1]

  for _ in range(Q):
    B, C = map(int, input().split(" "))
    if B in countA.keys():
      countA[C] += countA.pop(B)
      sum_A = 0
      for a in countA.items():
        sum_A += a[0]*a[1]
      print(sum_A)
    else:
      print(sum_A)


if __name__ == "__main__":
  resolve()
