s = gets.strip
n = gets.strip.to_i

n.times do
	line = gets.strip.split(" ")
	op = line[0]
	case op
	when "replace"
		a, b, p = line[1].to_i, line[2].to_i, line[3]
		s[a..b] = p
	when "reverse"
		a, b = line[1].to_i, line[2].to_i
		s[a..b] = s[a..b].reverse
	when "print"
		a, b = line[1].to_i, line[2].to_i
		puts s[a..b]
	end
end
