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: import sys
  
  input = sys.stdin.readline
  
  
  def main():
      text = input().rstrip()
      n = int(input().rstrip())
      for i in range(n):
          s = input().split()
          if s[0] == "print":
              print(text[int(s[1]) : int(s[2]) + 1])
          elif s[0] == "replace":
              new_text = ""
              new_text += text[: int(s[1])]
              new_text += s[3]
              new_text += text[int(s[2]) + 1 :]
              text = new_text
          elif s[0] == "reverse":
              new_text = ""
              new_text += text[: int(s[1])]
              for i in range(int(s[2]) - int(s[1]) + 1):
                  new_text += text[int(s[2]) - i]
              new_text += text[int(s[2]) + 1 :]
              text = new_text
  
  
  if __name__ == "__main__":
      main()
  
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"}]