s=string.gsub(io.read()," ","")
q=io.read("*n","*l")
query={}
for i=1,q do
    t=io.read("*n")
    if t==1 then
        s=string.reverse(s)
    else
        f=io.read("*n")
        c=string.gsub(io.read()," ","")
        if f==1 then
            s=c..s
        else
            s=s..c
        end
    end
end
print(s)