let () = Scanf.scanf "%s\n%d\n" @@ fun s q ->
  let qs = Array.init q @@ fun _ ->
    Scanf.scanf "%d" @@ function
      | 1 -> Scanf.scanf "\n" `Q1
      | 2 -> Scanf.scanf " %d %c\n" @@ fun f c -> `Q2 (f, c) in
  let (h, t) =
    Array.fold_left (fun (h, t) -> function
      | `Q1 -> (t, h)
      | `Q2 (1, c) -> (c :: h, t)
      | `Q2 (2, c) -> (h, c :: t))
    (Array.to_list (Array.init (String.length s) (String.get s)), []) qs in
  List.iter print_char h;
  List.iter print_char (List.rev t);
  print_newline ()