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: str = input()
  s = list(str)
  q = int(input())
  for i in range(q):
      Q = input()
      l = list(Q)
      if "print" in Q:
          for p in range(6):
              l.pop(0)
          for X in range(len(l)):
              if l[X] == " ":
                  x = X
          A = l[0:x]
          a = "".join(A)
          a = int(a)
          B = l[x + 1 : len(l)]
          b = "".join(B)
          b = int(b) + 1
          t = s[a:b]
          str = "".join(t)
          print(str)
      elif "reverse" in Q:
          for v in range(8):
              l.pop(0)
          for Y in range(len(l)):
              if l[Y] == " ":
                  y = Y
          A = l[0:y]
          a = "".join(A)
          a = int(a)
          B = l[y + 1 : len(l)]
          b = "".join(B)
          b = int(b) + 1
          t = s[a:b]
          t.reverse()
          s[a:b] = t
      elif "replace" in Q:
          for r in range(8):
              l.pop(0)
          for Z in range(len(l)):
              if l[Z] == " ":
                  z = Z
                  break
          N = 0
          while True:
              if l[z + N + 1] == " ":
                  n = z + N + 1
                  break
              else:
                  N += 1
          A = l[0:z]
          a = "".join(A)
          a = int(a)
          B = l[z + 1 : n]
          b = "".join(B)
          b = int(b) + 1
          t = l[n + 1 : len(l)]
          s[a:b] = t
  
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"}]