str = gets.chomp
q = gets.to_i

q.times do
    order, a, b, rep = gets.split
    f = a.to_i
    t = b.to_i
    case
    when order == "print"
        puts str[f..t]
    when order == "reverse"
        tmp1 = f > 0 ? str[0...f] : ""
        tmp2 = str[f..t].reverse
        tmp3 = (t + 1) <= (str.size - 1) ? str[(t + 1)..(str.size - 1)] : ""
        str = tmp1 + tmp2 + tmp3
    when order == "replace"
        tmp1 = f > 0 ? str[0...f] : ""
        tmp2 = (t + 1) <= (str.size - 1) ? str[(t + 1)..(str.size - 1)] : ""
        str = tmp1 + rep + tmp2
    end
end
