module AtCoder

open System
open System.Collections
open System.Collections.Generic
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 }
/// Exが存在することを前提にコードを書く

[<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

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

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

    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 QueryN =
    [ for _ in 1 .. Q ->
        let type' = get()
        match type' with
        | 1 -> One
        | _ ->
            let f = get()
            let c = get()
            Two(f, c) ]

let linkedList = LinkedList<_>()

S.ToCharArray() |> Array.iter (fun c -> linkedList.AddLast c |> ignore)

let mutable isFlip = false

type LinkedList<'a> with
    member __.PopFront(): 'a =
        let t = __.First.Value
        __.RemoveFirst()
        t
    member __.PopBack(): 'a =
        let t = __.Last.Value
        __.RemoveLast()
        t

QueryN
|> List.iter (fun q ->
    match q with
    | One -> isFlip <- not isFlip
    | Two(1, c) ->
        if not isFlip then linkedList.AddFirst c |> ignore
        else linkedList.AddLast c |> ignore
    | Two(_, c) ->
        if isFlip then linkedList.AddFirst c |> ignore
        else linkedList.AddLast c |> ignore)

let sb = StringBuilder()

while linkedList.Any() do
    linkedList.PopFront()
    |> sb.Append
    |> ignore

if not isFlip then sb.ToString()
else sb.ToString().Reversed()
|> Console.WriteLine



Measured memory_bytes: 45400