let () = Scanf.scanf "%d\n" @@ fun n ->
  let array = Array.make 100001 0 in
  for i = 0 to n-1 do
    Scanf.scanf "%d " @@ fun a -> array.(a) <- array.(a) + 1
  done;
  Scanf.scanf "%d\n" @@ fun q ->
    for i = 0 to q-1 do
      Scanf.scanf "%d %d\n" @@ fun b c -> array.(c) <- array.(c) + array.(b); array.(b) <- 0
    done;
  Printf.printf "%d\n" @@ Array.fold_left ( + ) 0 array