open Batteries

let s = read_line ()
let q = read_int ()

let string_rev s =
  let len = String.length s in
  String.init len (fun i -> s.[len - 1 - i])

let add_p result line_list =
    match List.nth line_list 1 with
    | "1" -> (List.nth line_list 2) ^ result
    | _ -> result ^ (List.nth line_list 2)


let change result line =
    match line.[0] with
    | '1' -> string_rev result
    | _ -> add_p result (String.split_on_char ' ' line)

let rec ans r s = 
    match s with
    | 0 -> r
    | _ -> ans (change r (read_line())) (s-1)

let _ = print_endline (ans s q)

