def _print(s, i, j)
  puts s[(i.to_i)..(j.to_i)]
end

def replace(s, i, j, r)
  s[(i.to_i)..(j.to_i)] = r
end

def reverse(s, i, j)
  p = s[(i.to_i)..(j.to_i)].reverse
  s[(i.to_i)..(j.to_i)] = p
end

s = gets.chomp
q = gets.chomp.to_i
q.times do
  f, *args = gets.chomp.split
  args.unshift s
  case f
  when "replace" then replace(*args)
  when "reverse" then reverse(*args)
  when "print" then _print(*args)
  end
end

