let () =
  let rec loop () =
    match read_line () with
      "-" -> ()
    | cards -> 
       let m = read_int () in
       let rec shuffle n cards =
         match n with
           0 -> print_endline cards
         | i -> let h = read_int () in
                let bottom = String.sub cards 0 h in
                let top = String.sub cards h @@ String.length cards - h  in
                shuffle (n-1) (top ^ bottom)
       in
       shuffle m cards;
       loop ()
  in
  loop ()
;;
