output_description: For each print command, print a string in a line.
input_description: In the first line, a string $str$ is given. $str$ consists of lowercase
  letters. In the second line, the number of commands q is given. In the next q
  lines, each command is given in the above mentioned format.
attempt: def print_ab(sent, a, b):
      res = sent[a : b + 1]
      return res
  
  
  def reverse_ab(sent, a, b):
      top = sent[:a]
      las = sent[b + 1 :]
      tag = sent[a : b + 1]
      n = len(tag)
      rev = ""
      for i in range(n):
          rev = rev + tag[n - i - 1]
      rev = top + rev + las
      return rev
  
  
  def replace_abp(sent, a, b, p):
      top = sent[:a]
      las = sent[b + 1 :]
      rep = top + p + las
      return rep
  
  
  # print(print_ab("xyz", 0, 2))
  # print(reverse_ab("abcde", 1, 3))
  # print(replace_abp("xyz", 0, 2, "abc"))
  
  sent = input()
  op = int(input())
  results = []
  for i in range(op):
      oder = list(map(str, input().split()))
      if oder[0] == "print":
          res = print_ab(sent, int(oder[1]), int(oder[2]))
          results.append(res)
      elif oder[0] == "reverse":
          sent = reverse_ab(sent, int(oder[1]), int(oder[2]))
      else:
          sent = replace_abp(sent, int(oder[1]), int(oder[2]), oder[3])
  
  for s in results:
      print(s)
  
problem_description: Transformation
  
    
  
  Write a program which performs a sequence of commands to a given string $str$.
  The command is one of:
  
    * print a b: print from the a-th character to the b-th character of $str$
    * reverse a b: reverse from the a-th character to the b-th character of $str$
    * replace a b p: replace from the a-th character to the b-th character of $str$ with p
  
  Note that the indices of $str$ start with 0.
samples: [{"input": "abcde\n    3\n    replace 1 3 xyz\n    reverse 0 2\n    print 1 4", "output": "xaze"}, {"input": "xyz\n    3\n    print 0 2\n    replace 0 2 abc\n    print 0 2", "output": "xyz\n    abc"}]