#!/usr/bin/ruby

def exe_print(a, b, str)
  str[a..b]
end

def extract_pre(a, str)
  if a == 0
    ""
  else
    str[0..a-1]
  end
end

def extract_post(b, str)
  if b == str.length-1
    ""
  else
    str[b+1..str.length]
  end
end

def exe_reverse(a, b, str)
  pre = extract_pre(a, str)
  post = extract_post(b, str)
  pre + str[a..b].reverse + post
end

def exe_replace(a, b, p, str)
  pre = extract_pre(a, str)
  post = extract_post(b, str)
  pre + p + post
end

def execute_command(command, str)
  command_list = command.split(" ")
  if command_list[0] == "print"
    print_str = exe_print(command_list[1].to_i, command_list[2].to_i, str)
    puts print_str
    str
  elsif command_list[0] == "reverse"
    return exe_reverse(command_list[1].to_i, command_list[2].to_i, str)
  elsif command_list[0] == "replace"
    str = exe_replace(command_list[1].to_i, command_list[2].to_i, command_list[3], str)
    return str
  end
end


str = $stdin.gets.chomp
q = $stdin.gets.to_i

while q > 0 do
  command = $stdin.gets
  str = execute_command(command, str)
  q -= 1
end