def main():
  N = int(input())
  A = list(map(int, input().split()))
  Q = int(input())
  map_ = []
  for _ in range(Q):
    b, c = list(map(int, input().split()))
    map_.append([b, c])

  mem = {}
  for a in A:
    if not(a in mem):
      mem[a] = 0
    mem[a] += 1

  sum_ = sum(A)
  for i in range(Q):
    from_, to_ = map_[i]
    idiff = 0
    if not(from_ in mem):
      print(sum_)
      break
    idiff = mem[from_]
    if not(to_ in mem):
      mem[to_] = 0
    mem[to_] += mem[from_]
    mem[from_] = 0
    diff = idiff * (to_ - from_)
    sum_ += diff
    # print(mem)
    print(sum_)


if(__name__ == '__main__'):
  main()