#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_9_D

class String
  def print(a,b)
      puts self[a..b]
  end
  def reverse(a,b)
      tmp = self.dup
      for i in 0..(b-a)
        tmp[a+i] = self[b-i]
      end
      tmp
  end
  def replace(a,b,p)
      tmp = self.dup
      for i in 0..(b-a)
        tmp[a+i] = p[i]
      end
      tmp
  end
  
end

str = gets.chomp
n = gets.to_i

n.times.each do
    data = gets.split
    if data[0]=="replace" 
        str = str.replace(data[1].to_i,data[2].to_i,data[3])
    elsif data[0] == "reverse"
        str = str.reverse(data[1].to_i,data[2].to_i)
    elsif data[0] == "print"
        str.print(data[1].to_i,data[2].to_i)
    end
end