#!/usr/bin/env ruby

if __FILE__ == $0 then
	s = gets.chomp
	q = gets.chomp.to_i

	q.times do
		op = gets.split
		a, b = op[1,2].map(&:to_i)
		p  = op[3]

		case op[0]
		when 'print' then
			puts s[a..b]
		when 'reverse'
            s = s[0,a] + s[a..b].reverse + s[b+1..-1]
		when 'replace'
            s = s[0,a] + p + s[b+1..-1]
		end
	end
end
