def find_atob(str, a, b)
  str_atob = str[a..b]
  return str_atob
end

def reverse_atob(str, str_atob)
  str.gsub!(str_atob, str_atob.reverse)
  return str
end

def replace_atob(str, str_atob, p)
  str.gsub!(str_atob, p)
  return str
end

def execute_orders(str, q, order_array)
  for i in 0..(q-1)
    str_atob = find_atob(str, order_array[i][1].to_i, order_array[i][2].to_i)
    if order_array[i][0] == "replace"
      replace_atob(str, str_atob, order_array[i][3])
    elsif order_array[i][0] == "reverse"
      reverse_atob(str, str_atob)
    else
      puts str_atob
    end
  end
end

str = gets.chomp
q = gets.chomp.to_i
order_array = []
for i in 0..(q-1)
  order = gets.chomp.split
  order_array.push(order)
end

execute_orders(str, q, order_array)