program String_Formation
    implicit none
    character(100000):: s
    character(1):: fs(200000), bs(200000), ss(300000)
    character(5):: cq
    integer(4):: q
    integer(4):: i, fi, bi
    logical:: flip

    flip = .false.

    read*, s
    read*, q

    fi=0
    bi=0

    do i=1, q
        read(*,'(5a)') cq
        if (cq(1:1) == '1') then
            flip = .not. flip
            cycle
        end if

        if (cq(3:3) == '1' .neqv. flip) then
            fi=fi+1
            fs(fi) = cq(5:5)
        else
            bi=bi+1
            bs(bi) = cq(5:5)
        end if
    end do

    do i=1, len_trim(s)
        ss(i) = s(i:i)
    end do



    if (flip) then
        print*, bs(bi:1:-1) , ss(len_trim(s):1:-1) , fs(1:fi)
    else
        print*, fs(fi:1:-1) , ss(1:len_trim(s)) , bs(1:bi)
    end if
end program String_Formation