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

def myprint(str, a, b)
  return str[a..b]
end
def myreverse(str, a, b)
  str[a..b] = str[a..b].reverse
  return str
end
def myreplace(str, a, b, p)
  str[a..b] = p
  return str
end

while line = gets
  cmds = line.chomp.split(' ')
  if cmds[0] == 'print'
    str = myprint(str, cmds[1].to_i, cmds[2].to_i)
    puts str
  elsif cmds[0] == 'reverse'
    str = myreverse(str, cmds[1].to_i, cmds[2].to_i)
  elsif cmds[0] == 'replace'
    str = myreplace(str, cmds[1].to_i, cmds[2].to_i, cmds[3])
  end
end