let () =
  let num = Array.make 100001 0 in
  let sum = ref 0 in
  Scanf.scanf "%d\n" @@ fun n ->
  for i = 0 to n - 1 do
    Scanf.scanf "%d " @@ fun d ->
    num.(d) <- num.(d) + 1; sum := !sum + d
  done;
  Scanf.scanf "%d\n" @@ fun q ->
  for i = 0 to q - 1 do
    Scanf.scanf "%d %d\n" @@ fun b c ->
    sum := !sum + (c - b) * num.(b); num.(c) <- num.(c) + num.(b); num.(b) <- 0;
    Printf.printf "%d\n" !sum
  done;