let st = stdin.ReadLine() |> Seq.toList |> List.map string
let q = stdin.ReadLine() |> int
let qr = [1..q] |> List.map (fun _ -> stdin.ReadLine().Split())
let rec f i s =
    if i=q then s |> List.reduce (fun ans x -> ans + x)
    elif qr.[i].[0]="1" then f (i+1) (List.rev s)
    elif qr.[i].[1]="1" then f (i+1) (List.append [qr.[i].[2]] s)
    else f (i+1) (List.append s [qr.[i].[2]])
f 0 st |> stdout.WriteLine