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