def print(str, a, b)
  return str.slice(a..b)
end

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

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

str = gets.chomp.to_s
n = gets.to_i

n.times{
  s, a, b, p =gets.split.map(&:to_i)
  a = a.to_i
  b = b.to_i

  if s == "print"
    puts print(str, a, b)
  elsif  s == "reverse"
    str = reverse(str, a, b)
  else
    str = replace(str, a, b, p)
  end
}