module AtCoder

open System
open System.Collections
open System.IO
open System.Linq
open System.Text

module NumericLiteralG =
    let inline FromZero(): ^a = LanguagePrimitives.GenericZero
    let inline FromOne(): ^a = LanguagePrimitives.GenericOne
    let inline FromInt32 n = Seq.sumBy (fun _ -> FromOne()) { 1 .. n }

[<AutoOpen>]
module Ex =
    type long = int64

    type double = float
    /// format対策
    let inline def(): 'a = Unchecked.defaultof<'a>

    let inline long x = int64 x
    let inline double x = float x
    let inline (+=) (x: ^a byref) (y: ^a) = x <- x + y
    let inline (-=) (x: ^a byref) (y: ^a) = x <- x - y

    let inline postIncr (x: ^a byref): ^a =
        x <- x + 1G
        x - 1G

    let inline preIncr (x: ^a byref): ^a =
        x <- x + 1G
        x

    let inline postDecr (x: ^a byref): ^a =
        x <- x - 1G
        x + 1G

    let inline preDecr (x: ^a byref): ^a =
        x <- x - 1G
        x

    type String with
        member __.Reversed() = new string(__.Reverse().ToArray())

[<AutoOpen>]
module Input =
    type ConvertTrait< ^a> =
        { FromStr: string -> ^a }

    module Internal =

        type ConvertBuiltin = ConvertBuiltin
            with
                static member inline ConvertImpl(_: System.Int32): ConvertTrait<System.Int32> = { FromStr = int }
                static member inline ConvertImpl(_: System.Int64): ConvertTrait<System.Int64> = { FromStr = long }
                static member inline ConvertImpl(_: System.Double): ConvertTrait<System.Double> = { FromStr = double }
                static member inline ConvertImpl(_: System.Char): ConvertTrait<System.Char> = { FromStr = char }
                static member inline ConvertImpl(_: System.String): ConvertTrait<System.String> = { FromStr = id }

        let inline getImpl (builtin: ^builtin) (_: ConvertTrait< ^a >) =
            ((^builtin or ^a): (static member ConvertImpl: 'a -> ConvertTrait< ^a >) (def()))

        let inline fromStr (x: string): ^a =
            (getImpl ConvertBuiltin (Unchecked.defaultof<ConvertTrait< ^a >>)).FromStr(x)

        type Input() =


            [<Literal>]
            let size = 5000

            let stream = Console.OpenStandardInput()
            let buffer = Array.zeroCreate size
            let mutable (ptr, bufferSize) = (0, 0)

            let hasNextByte(): bool =
                if ptr < bufferSize then
                    true
                else
                    ptr <- 0
                    bufferSize <- stream.Read(buffer, 0, size)
                    bufferSize > 0

            let readByte(): byte =
                if hasNextByte() then buffer.[postIncr &ptr]
                else failwith "buffer empty"

            let isAscii (c: int): bool = int '!' <= c && c <= int '~'

            let nextChar(): char =
                let mutable b = readByte()
                while (not << isAscii << int) b do
                    b <- readByte()
                char b

            let next(): string =
                let sb = StringBuilder()
                let mutable c = byte <| nextChar()
                while (isAscii << int) c do
                    sb.Append(char c) |> ignore
                    c <- readByte()
                sb.ToString()

            member __.String = next()

        let input = Input()

    let inline get(): ^a = Internal.fromStr (Internal.input.String)
    let inline getString(): string = get()
    let inline getInt(): int = get()

let S = getString()
let Q = get()

type Query =
    | One
    | Two of int * char

let queries =
    [ for i in 1 .. Q ->
        let type' = get()
        match type' with
        | 1 -> One
        | _ ->
            let f = get()
            let c = get()
            Two(f, c) ]

queries
|> List.fold (fun (isFlip, sb: StringBuilder) q ->
    match q with
    | One -> (not isFlip, sb)
    | Two(1, c) ->
        if not isFlip then isFlip, (sb.Insert(0, c))
        else (isFlip, sb.Append(c))
    | Two(_, c) ->
        if not isFlip then (isFlip, sb.Append(c))
        else isFlip, (sb.Insert(0, c))) (false, StringBuilder().Append(S))
|> fun (isFlip, sb) ->
    if isFlip then sb.ToString().Reversed()
    else sb.ToString()
|> Console.WriteLine
