str = gets.chomp
gets.to_i.times{
	code = gets.split
	range = code[1].to_i..code[2].to_i
	case code[0]
	when 'print'
		puts str[range]
	when 'replace'
		str[range] = code[3]
	when 'reverse'
		str[range] = str[range].chars.reverse.join
	end
}