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

def reverse(str, a, b)
  (a > 0 ? str[0..(a - 1)] : "") << str[a..b].reverse << (b < str.length ? str[(b + 1)..(str.length - 1)] : "")
end

def replace(str, a, b, p)
  (a > 0 ? str[0..(a - 1)] : "") << p << (b < str.length ? str[(b + 1)..(str.length - 1)] : "")
end

str = gets.chomp
q = gets.to_i

(1..q).each {
  inputs = gets.chomp.split(" ")
  op = inputs.first
  a, b = inputs.drop(1).take(2).map(&:to_i)
  case inputs.shift
    when "print"
      print(str, a, b)
    when "reverse"
      str = reverse(str, a, b)
    when "replace"
      str = replace(str, a, b, inputs.last)
  end
}