let s = read_line () in
let len = String.length s in
Scanf.scanf " %d" (fun q ->
    let buf = Array.make 500000 ' ' in
    String.iteri (fun i v -> buf.(i + 200000) <- v) s;
    let rec loop qq rev first last =
        if qq > 0 then (
            let t = Scanf.scanf " %d" (fun t -> t) in
            if t = 1 then (
                loop (qq - 1) (not rev) first last
            ) else (
                let f, c = Scanf.scanf " %d %c" (fun f c -> f, c) in
                match f, rev with
                | 1, false
                | 2, true -> (buf.(first - 1) <- c; loop (qq - 1) rev (first - 1) last)
                | _ -> (buf.(last + 1) <- c; loop (qq - 1) rev first (last + 1))
            )
        ) else (
            let len = last - first + 1 in
            let s =
                if rev then
                    String.init len (fun i -> buf.(last - i))
                else
                    String.init len (fun i -> buf.(first + i))
            in
            print_endline s
        )
    in
    loop q false 200000 (200000 + len - 1);
)