s=gets.chomp
q=gets.to_i
while line=gets
  (c,a,b,p)=line.split
  a=a.to_i
  b=b.to_i
  s1=(a>0) ? s[0..a-1] : ""
  s2=(b<s.size) ? s[b+1..s.size] : ""
  puts s[a..b] if c=="print"
  s=s1 + s[a..b].reverse + s2 if c=="reverse"
  s=s1 + p + s2 if c=="replace"
end