let () =
  let rotate n str =
    String.sub str n (String.length str - n) ^ String.sub str 0 n
  in
  let rec shuffle card = function
      0 -> card
    | i ->
      let h = read_int () in
      shuffle (rotate h card) (i-1)
  in
  let rec loop () =
    match read_line () with
      "-"  -> ()
    | card ->
      let times = read_int () in
      print_endline (shuffle card times);
      loop ()
  in loop ()
