let split_string ?(pattern=" ") = Str.split @@ Str.regexp pattern
let s = read_line ()
let q = Scanf.sscanf (read_line ()) "%d" @@ fun q -> q
let qq = Array.init q @@ fun _ -> read_line () |> split_string |> Array.of_list

let (s, rev) = Array.fold_left (fun (s, rev) qr ->
  if qr.(0) = "1" then (s, not rev)
  else
    let [| _; f; c |] = qr in
    let t = (f = "1" && not rev) || (f = "2" && rev ) in
    ((if t then c else "") ^ s ^ (if not t then c else ""), rev)
) (s, false) qq

let () = 
  if rev then begin
    for i = String.length s - 1 downto 0 do
      print_char s.[i]
    done;
    print_newline ()
  end
  else print_endline s