=begin
  1, print,reverse,replace それぞれメソッドを作る
=end

def pri(str, a, b)
  puts str[a..b]
end

def rev(str, a, b)
  x = str.slice!(a..b)
  str.insert(a, x.reverse)
  return str
end

def rep(str,a, b, p)
  str.slice!(a..b)
  str.insert(a,p)
  return str
end

s = gets.chomp
n = gets.to_i
n.times do
  input = gets.chomp.split
  if input[0] == "print"
    pri(s, input[1].to_i, input[2].to_i)
  elsif input[0] == "reverse"
    rev(s, input[1].to_i, input[2].to_i)
  else
    rep(s, input[1].to_i, input[2].to_i, input[3])
  end
end
