str = STDIN.gets.chomp
commands = STDIN.gets.chomp.to_i

1.upto(commands) {
	command = STDIN.gets.chomp.split(" ")
	command[1], command[2] = [command[1].to_i, command[2].to_i]
	
	if command[0].eql?("print") then
		print str[command[1]..command[2]], "\n"
	elsif command[0].eql?("replace") then
		str[command[1]..command[2]] = command[3]
	elsif command[0].eql?("reverse") then
		str_tmp = String.new(str)
		diff = command[2] - command[1]
		reverse_start = command[2] - str.length
		0.upto(diff) {|d|
			str[command[1] + d] = str_tmp[reverse_start - d]
		}
	end
} 
