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