s = gets.chomp
q = gets.to_i
q.times {
	cmd = gets.split( " " )
	a = cmd[1].to_i
	b = cmd[2].to_i
	case cmd[0]
	when "print"
		puts( "#{ s[ a..b ] }" )
	when "reverse"
		s[ a..b ] = s[ a..b ].reverse
	when "replace"
		s[ a..b ] = cmd[3]
	end
}