let s, q = Scanf.scanf " %s %d" @@ fun a b -> a, b
let r, fs, bs = ref 0, ref [], ref []
let g s = String.(init (length s) @@ fun i -> s.[length s - i - 1])
let _ = Scanf.(for _ = 1 to q do scanf " %d" @@ fun t -> if t = 1 then r := !r lxor 1 else scanf " %d %s" @@ fun f c -> if !r = f - 1 then fs := c :: !fs else bs := c :: !bs done); List.(if !r = 0 then bs := rev !bs else fs := rev !fs); let f, b = String.(concat "" !fs, concat "" !bs) in print_endline @@ if !r = 0 then f ^ s ^ b else b ^ g s ^ f