# Your code here!
def t_print(str, first, last)
    ((first.to_i)..(last.to_i)).each{|i|
        print str[i]
    }
    puts ""
end

def t_replace(str, first, last, rep_str)
    ((first.to_i)..(last.to_i)).each_with_index{|i, j|
        str[i] = rep_str[j]
    }
end

def t_reverse(str, first, last)
    temp = String.new(str)
    ((first.to_i)..(last.to_i)).each_with_index{|i, j|
        str[i] = temp[last.to_i - j]
    }
end

# Main
str = gets.chomp
loop = gets.to_i

loop.times{|i|
    order = gets.split
    case order[0]
        when "print" then t_print(str, order[1], order[2])
        when "replace" then t_replace(str, order[1], order[2], order[3])
        when "reverse" then t_reverse(str, order[1], order[2])
    end
}
