open System
open System.Collections
open System.Collections.Generic

[<AutoOpen>]
module FastIO =
    let reader = new IO.StreamReader(new IO.BufferedStream(Console.OpenStandardInput()))
    let inline read f = reader.ReadLine() |> f
    let inline reada f = reader.ReadLine().Split() |> Array.map f
    let inline readChars() = read string |> Seq.toArray
    let inline readInts() = readChars() |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

    let writer = new IO.StreamWriter(new IO.BufferedStream(Console.OpenStandardOutput()))
    let inline write (s: string) = writer.Write s
    let inline writeln (s: string) = writer.WriteLine s
    let inline puts (s: ^a) = string s |> writeln

    let inline ioDispose() =
        reader.Dispose()
        writer.Dispose()

// -----------------------------------------------------------------------------------------------------
type Deque<'T>(front, rBack) =
    let mutable hashCode = None
    member internal this.front = front
    member internal this.rBack = rBack

    override this.GetHashCode() =
        match hashCode with
        | None ->
            let mutable hash = 1
            for x in this do
                hash <- 31 * hash + Unchecked.hash x
            hashCode <- Some hash
            hash
        | Some hash -> hash

    override this.Equals(other) =
        match other with
        | :? (Deque<'T>) as y ->
            if this.Length <> y.Length then false
            else if this.GetHashCode() <> y.GetHashCode() then false
            else Seq.forall2 (Unchecked.equals) this y
        | _ -> false

    member this.Conj x = Deque(front, x :: rBack)

    member this.Cons x = Deque(x :: front, rBack)

    member this.Head =
        match front, rBack with
        | [], [] -> raise (new System.Exception("Deque is empty"))
        | hd :: tl, _ -> hd
        | [], xs -> List.rev xs |> List.head

    member this.TryHead: 'T option =
        match front, rBack with
        | [], [] -> None
        | hd :: tl, _ -> Some(hd)
        | [], xs ->
            let x = List.rev xs |> List.head
            Some(x)

    member this.Initial =
        match front, rBack with
        | [], [] -> raise (new System.Exception("Deque is empty"))
        | _, x :: xs -> Deque(front, xs)
        | _, [] ->
            let half = front.Length / 2
            let a = Array.ofList front
            let frontA = Array.create half front.Head
            let rBackA = Array.create ((front.Length - half) - 1) front.Head
            Array.blit a 0 frontA 0 frontA.Length
            Array.blit a frontA.Length rBackA 0 rBackA.Length
            let rBackA' = Array.rev rBackA
            Deque(List.ofArray frontA, List.ofArray rBackA')

    member this.TryInitial =
        match front, rBack with
        | [], [] -> None
        | _, x :: xs -> Some(Deque(front, xs))
        | _, [] ->
            let half = front.Length / 2
            let a = Array.ofList front
            let frontA = Array.create half front.Head
            let rBackA = Array.create ((front.Length - half) - 1) front.Head
            Array.blit a 0 frontA 0 frontA.Length
            Array.blit a frontA.Length rBackA 0 rBackA.Length
            let rBackA' = Array.rev rBackA
            Some(Deque(List.ofArray frontA, List.ofArray rBackA'))

    member this.IsEmpty =
        match front, rBack with
        | [], [] -> true
        | _ -> false

    member this.Last =
        match front, rBack with
        | [], [] -> raise (new System.Exception("Deque is empty"))
        | xs, [] -> List.rev xs |> List.head
        | _, hd :: tl -> hd

    member this.TryLast =
        match front, rBack with
        | [], [] -> None
        | xs, [] -> Some(List.rev xs |> List.head)
        | _, hd :: tl -> Some(hd)

    member this.Length = front.Length + rBack.Length

    member this.Rev = (new Deque<'T>(rBack, front))

    member this.Tail =
        match front, rBack with
        | [], [] -> raise (new System.Exception("Deque is empty"))
        | x :: xs, _ -> Deque(xs, rBack)
        | _, _ ->
            let half = rBack.Length / 2
            let a = Array.ofList rBack
            let frontA = Array.create half rBack.Head
            let rBackA = Array.create ((rBack.Length - half) - 1) rBack.Head
            Array.blit a 0 rBackA 0 rBackA.Length
            Array.blit a rBackA.Length frontA 0 frontA.Length
            let frontA' = Array.rev frontA
            Deque(List.ofArray frontA', List.ofArray rBackA)

    member this.TryTail =
        match front, rBack with
        | [], [] -> None
        | x :: xs, _ -> Some(Deque(xs, rBack))
        | _, _ ->
            let half = rBack.Length / 2
            let a = Array.ofList rBack
            let frontA = Array.create half rBack.Head
            let rBackA = Array.create ((rBack.Length - half) - 1) rBack.Head
            Array.blit a 0 rBackA 0 rBackA.Length
            Array.blit a rBackA.Length frontA 0 frontA.Length
            let frontA' = Array.rev frontA
            Some(Deque(List.ofArray frontA', List.ofArray rBackA))

    member this.Uncons =
        match front, rBack with
        | [], [] -> raise (new System.Exception("Deque is empty"))
        | _, _ -> this.Head, this.Tail

    member this.TryUncons =
        match front, rBack with
        | [], [] -> None
        | _, _ -> Some(this.Head, this.Tail)

    member this.Unconj =
        match front, rBack with
        | [], [] -> raise (new System.Exception("Deque is empty"))
        | _, _ -> this.Initial, this.Last

    member this.TryUnconj =
        match front, rBack with
        | [], [] -> None
        | _, _ -> Some(this.Initial, this.Last)

    interface IReadOnlyCollection<'T> with
        member this.Count = this.Length

        member this.GetEnumerator() =
            let e =
                seq {
                    yield! front
                    yield! (List.rev rBack)
                }
            e.GetEnumerator()

        member this.GetEnumerator() = (this :> _ seq).GetEnumerator() :> IEnumerator
// -----------------------------------------------------------------------------------------------------

let main() =
    let S = read string
    let mutable deq = Deque(List.ofSeq S, [])
    let mutable flg = true
    let Q = read int
    for i in 0 .. Q - 1 do
        let q = reada string
        match q.[0] with
        | "1" -> flg <- not flg
        | _ ->
            let c = q.[2].[0]
            match q.[1] with
            | "1" ->
                if flg then deq <- deq.Cons(c) else deq <- deq.Conj(c)
            | _ ->
                if flg then deq <- deq.Conj(c) else deq <- deq.Cons(c)

    let ans = seq { yield! deq } |> String.Concat
    if flg then
        puts ans
    else
        ans
        |> Seq.rev
        |> Seq.map string
        |> String.concat ""
        |> puts
    ()

// -----------------------------------------------------------------------------------------------------
main()
ioDispose()
