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

def reverse(s, a, b)
  chunk = s[a..b]
  s[a..b] = chunk.reverse
  s
end

def replace(s, a, b, p)
  s[a..b] = p
  s
end

s = gets.chomp
q = gets.chomp.to_i

q.times do
  c = gets.chomp.split
  c[1] = c[1].to_i
  c[2] = c[2].to_i
  case c[0]
  when "print" then print(s, c[1], c[2])
  when "reverse" then s = reverse(s, c[1], c[2])
  when "replace" then s = replace(s, c[1], c[2], c[3])
  end
end