str = gets.chomp
n = gets.chomp.to_i
while line = gets
  cmd, a, b, p = line.chomp.split(' ')
  a = a.to_i
  b = b.to_i
  if cmd == 'print'
    puts str[a..b]
  elsif cmd == 'reverse'
    str[a..b] = str[a..b].reverse
  elsif cmd == 'replace'
    str[a..b] = p
  end
end