$debug=0
def aux(s,cmds)
  puts "s: #{s}" if $debug>1
  while cmds.length>0
    cmd = cmds.shift
    op= cmd[0]
    a = cmd[1].to_i
    b = cmd[2].to_i
    p = cmd[3]
    len=s.length
    puts "op: #{op}, a: #{a}, b: #{b}, p: #{p}"  if $debug>1
    if op=="print"
      puts s.slice(a..b)
    elsif op=="reverse"
      s = s.slice(0,a) + s.slice(a..b).reverse + s.slice(b+1,len-b)
    elsif op=="replace"
      s = s.slice(0,a) + p + s.slice(b+1,len-b)
    else
      abort("no such command: #{op}")
    end
    puts "s: #{s}"  if $debug>1

  end
  s

end
s="abcde"
a=1
b=3

def main
  fh=STDIN
  #fh=File.new("x.txt", "r")
  s = fh.gets.chomp
  n = fh.gets.chomp.to_i
  cmds = []
  n.times {|i|
    cmds <<fh.gets.chomp.split
  }
  aux(s,cmds)
end

if $0 == __FILE__ then
  main
end
