Write a program that executes a series of commands on a given string, "str". The commands include "print a b" (printing characters from the a-th to the b-th position of "str"), "reverse a b" (reversing characters from the a-th to the b-th position of "str"), and "replace a b p" (replacing characters from the a-th to the b-th position of "str" with string "p"). Note that the indices of "str" start from 0.

Input:
- The first line contains the string "str" consisting of lowercase letters.
- The second line contains the number of commands, "q".
- The next "q" lines contain each command in the specified format.

Output:
- For each "print" command, print the resulting string on a new line.

Constraints:
- 1 ≤ length of "str" ≤ 1000
- 1 ≤ q ≤ 100
- 0 ≤ a ≤ b < length of "str"
- For the "replace" command, the length of "p" is equal to (b - a + 1).

Sample Input 1:
```
abcde
3
replace 1 3 xyz
reverse 0 2
print 1 4
```

Sample Output 1:
```
xaze
```

Sample Input 2:
```
xyz
3
print 0 2
replace 0 2 abc
print 0 2
```

Sample Output 2:
```
xyz
abc
```

# Buggy version:
def main():

    strTxt = input()
    n = int(input())
    for _ in range(n):
        strCmd = input().split()
        
        if strCmd[0] == 'print':
            funcPrint(strTxt, int(strCmd[1]), int(strCmd[2]))
        elif strCmd[0] == 'reverse':
            strTxt = funcReverse(strTxt, int(strCmd[1]), int(strCmd[2]))
        elif strCmd[0] == 'replace':
            strTxt = funcReplace(strTxt, int(strCmd[1]), int(strCmd[2]), strCmd[3])

def funcPrint(strInput: str,a: int,b: int):
    print(strInput[a:b+1])

def funcReverse(strInput: str,a: int,b: int):
    return strInput[:a]+strInput[::-1][a:b+1]+strInput[b+1:]

def funcReplace(strInput: str,a: int,b: int, strAfter: str):
    return strInput[:a]+strAfter+strInput[b+1:]


if __name__ == '__main__':
    main()



# Fixed version:
def main():

    strTxt = input()
    n = int(input())
    for _ in range(n):
        strCmd = input().split()
        
        if strCmd[0] == 'print':
            funcPrint(strTxt, int(strCmd[1]), int(strCmd[2]))
        elif strCmd[0] == 'reverse':
            strTxt = funcReverse(strTxt, int(strCmd[1]), int(strCmd[2]))
        elif strCmd[0] == 'replace':
            strTxt = funcReplace(strTxt, int(strCmd[1]), int(strCmd[2]), strCmd[3])

def funcPrint(strInput: str,a: int,b: int):
    print(strInput[a:b+1])

def funcReverse(strInput: str,a: int,b: int):
    return strInput[:a]+strInput[a:b+1][::-1]+strInput[b+1:]

def funcReplace(strInput: str,a: int,b: int, strAfter: str):
    return strInput[:a]+strAfter+strInput[b+1:]


if __name__ == '__main__':
    main()

# Buggy version:
S = str(input())
N = int(input())
for _i in range(N):
    line = input().split()
    start = int(line[1])
    end = int(line[2])

    if line[0] == 'print':
        print(S[start:end + 1])
    if line[0] == 'reverse':
        reversed_word = list(S[start:end + 1])
        reversed_word.reverse()
        S = S[:start] + ''.join(reversed_word) + S[end + 1:]
    if line[0] == 'replace':
        S = S[:start] + line[3] + S[end + 1:]
        print(S)



# Fixed version:
S = str(input())
N = int(input())
for _i in range(N):
    line = input().split()
    start = int(line[1])
    end = int(line[2])

    if line[0] == 'print':
        print(S[start:end + 1])
    if line[0] == 'reverse':
        reversed_word = list(S[start:end + 1])
        reversed_word.reverse()
        S = S[:start] + ''.join(reversed_word) + S[end + 1:]
    if line[0] == 'replace':
        S = S[:start] + line[3] + S[end + 1:]

# Buggy version:
text = input()
count = int(input())

for c in range(count):
    args = input().split()
    (a,b) = [int(x) for x in args[1:3]]
    if args[0] == 'print':
        print(text[a:b + 1])
    elif args[0] == 'reverse':
        text = text[0:a] + text[a:b][::-1] + text[b + 1:]
    elif args[0] == 'replace':
        text = text[0:a] +  args[3] + text[b + 1:]

# Fixed version:
text = input()
count = int(input())

for c in range(count):
    args = input().split()
    (a, b) = [int(x) for x in args[1:3]]
    if args[0] == 'print':
        print(text[a:b + 1])
    elif args[0] == 'reverse':
        text = text[0:a] + text[a:b + 1][::-1] + text[b + 1:]
    elif args[0] == 'replace':
        text = text[0:a] +  args[3] + text[b + 1:]

# Buggy version:
if __name__ == '__main__':
    s = input()
    q = int(input())
    for i in range(q):
        code = input().split()
        op, a, b = code[0], int(code[1]), int(code[2])
        if op == 'print':
            print(s[a:b+1])
        elif op == 'reverse':
            s = s[:a] + s[a:b+1][::-1] + s[b+1:]
        elif op == 'replace':
            s = s[:a] + p + s[b+1:]

# Fixed version:
if __name__ == '__main__':
    s = input()
    q = int(input())
    for i in range(q):
        code = input().split()
        op, a, b = code[0], int(code[1]), int(code[2])
        if op == 'print':
            print(s[a:b+1])
        elif op == 'reverse':
            s = s[:a] + s[a:b+1][::-1] + s[b+1:]
        elif op == 'replace':
            s = s[:a] + code[3] + s[b+1:]

# Buggy version:
string = input()
n = int(input())
for _ in range(n):
    query = input().split()
    if query[0] == 'replace':
        op, a, b, p = query
        a, b = int(a), int(b)
        string = string[:a] + p * (b - a + 1) + string[b + 1:]
    elif query[0] == 'reverse':
        op, a, b = query
        a, b = int(a), int(b)
        string = string[:a] + ''.join(reversed(string[a:b + 1])) + string[b + 1:]
    elif query[0] == 'print':
        op, a, b = query
        a, b = int(a), int(b)
        print(string[a: b + 1])

# Fixed version:
string = input()
n = int(input())
for _ in range(n):
    query = input().split()
    if query[0] == 'replace':
        op, a, b, p = query
        a, b = int(a), int(b)
        string = string[:a] + p + string[b + 1:]
    elif query[0] == 'reverse':
        op, a, b = query
        a, b = int(a), int(b)
        string = string[:a] + ''.join(reversed(string[a:b + 1])) + string[b + 1:]
    elif query[0] == 'print':
        op, a, b = query
        a, b = int(a), int(b)
        print(string[a: b + 1])

# Buggy version:
s = input()
n = int(input())
for _ in range(n):
    line = input().split()
    command, args = line[0], line[1:]
    if command == 'replace':
        start = int(args[0])
        end = int(args[1]) + 1
        s = s[:start] + args[2] + s[end:]
    elif command == 'reverse':
        start = int(args[0])
        end = int(args[1]) + 1
        s = s[:start] + str(''.join(list(reversed(s[start:end])))) + s[end:]
    elif command == 'print':
        print(s)

# Fixed version:
s = input()
n = int(input())
for _ in range(n):
    line = input().split()
    command, args = line[0], line[1:]
    start = int(args[0])
    end = int(args[1]) + 1
    if command == 'replace':
        s = s[:start] + args[2] + s[end:]
    elif command == 'reverse':
        s = s[:start] + str(''.join(list(reversed(s[start:end])))) + s[end:]
    elif command == 'print':
        print(s[start:end])

# Buggy version:
#   ????????? str ?????????????????????????????????????????????????????????????????°??????

#   ?????\????±??????????str????¨??????\???????????????
str = list(input())
str = "".join(str)
#   ?????\???????????°p????¨??????\???????????????
p = int(input())
#   p??????????????????????????????????????????
orderList = [0 for i in range(p)]
for i in range(0, p):
    orderList[i] = list(input())
    orderList[i] = "".join(orderList[i]).split()
    if orderList[i][0] == "print":
        print("{0}".format(str[int(orderList[i][1]) - 1:int(orderList[i][2])]))
    elif orderList[i][0] == "reverse":
        str = str[0:int(orderList[i][1]) - 1] + str[-len(str) + int(orderList[i][2]) - 1:-len(str) + int(orderList[i][1]) - 2:-1] + str[int(orderList[i][2]):len(str)]
    elif orderList[i][0] == "replace":
        #   ??????????????¨?????????replace_str
        replace_str = str[:int(orderList[i][1]) - 1]
        for j in range(0, int(orderList[i][2])):
            replace_str += orderList[i][3]
        replace_str += str[int(orderList[i][2]):]
        str = replace_str

# Fixed version:
#   ????????? str ?????????????????????????????????????????????????????????????????°??????

#   ?????\????±??????????str????¨??????\???????????????
str = list(input())
str = "".join(str)
#   ?????\???????????°p????¨??????\???????????????
p = int(input())
#   p??????????????????????????????????????????
orderList = [0 for i in range(p)]
for i in range(0, p):
    orderList[i] = list(input())
    orderList[i] = "".join(orderList[i]).split()
    if orderList[i][0] == "print":
        print("{0}".format(str[int(orderList[i][1]):int(orderList[i][2]) + 1]))
    elif orderList[i][0] == "reverse":
        str = str[0:int(orderList[i][1])] + str[-len(str) + int(orderList[i][2]):-len(str) + int(orderList[i][1]) - 1:-1] + str[int(orderList[i][2]) + 1:]
    elif orderList[i][0] == "replace":
        str = str[:int(orderList[i][1])] + orderList[i][3] + str[int(orderList[i][2]) + 1:]

# Buggy version:

s = input()
????
for i in range(int(input())):
????????cmd = input().split()
????????a,b = [int(x) for x in cmd[1:3]]
????
????????if cmd[0] == 'print':
????????????????print(s[a:b+1])
????????elif cmd[0] == 'reverse':
????????????????s = s[:a] + s[a:b+1][::-1] + s[b+1:]
????????elif cmd[0] == 'replace':
????????????????s = s[:a] + cmd[3] + s[b+1:]

# Fixed version:
s = input()
 
for i in range(int(input())):
    cmd = input().split()
    a, b = int(cmd[1]), int(cmd[2])
 
    if cmd[0] == 'print':
        print(s[a:b+1])
    elif cmd[0] == 'reverse':
        s = s[:a] + s[a:b+1][::-1] + s[b+1:]
    elif cmd[0] == 'replace':
        s = s[:a] + cmd[3] + s[b+1:]

# Buggy version:
s = input()
n = int(input())
for i in range(n):
    p = input().split()
    
    a, b = [int(x) for x in p[1:3]]
    if p[0]=="print":
        print(s[a:b+1])
    if p[0]=="replace":
        s = s[:a] + p[3] + s[b+1:]
    if p[0]=="reverse":
        s = s[:a] + s[a:b+1:-1] + s[b+1:]

# Fixed version:
s = input()
n = int(input())

for i in range(n):
    p = input().split()

    a, b = [int(x) for x in p[1:3]]
    if p[0]=="print":
        print(s[a:b+1])
    elif p[0]=="replace":
        s = s[:a] + p[3] + s[b+1:]
    elif p[0]=="reverse":
        s = s[:a] + s[a:b+1][::-1] + s[b+1:]

# Buggy version:
string = input()
q = int(input())
for c in range(0,q):
    instruction = input().split(' ')
    if instruction[0] == 'print':
        print(string[int(instruction[1]):int(instruction[2]) + 1])
    elif instruction[0] == 'reverse':
        string = string.replace(string[int(instruction[1]):int(instruction[2])+1], string[int(instruction[1]):int(instruction[2])+1][::-1], 1)
    elif instruction[0] == 'replace':
        string = string[:int(instruction[1])] + instruction[3] + string[int(instruction[1])+1:]

# Fixed version:
string = input()
q = int(input())
for c in range(0,q):
    instruction = input().split(' ')
    if instruction[0] == 'print':
        print(string[int(instruction[1]):int(instruction[2]) + 1])
    elif instruction[0] == 'reverse':
        string = string.replace(string[int(instruction[1]):int(instruction[2])+1], string[int(instruction[1]):int(instruction[2])+1][::-1], 1)
    elif instruction[0] == 'replace':
        string = string[:int(instruction[1])] + instruction[3] + string[int(instruction[2])+1:]

# Buggy version:
line = input()
n = int(input())
for i in range(n):
    order = input().split()
    if order[0] == "print":
        print(line[int(order[1])-1:int(order[2])-1])
    elif order[0] == "reverse":
        tmp = line[int(order[1]) - 1:int(order[2]) - 1]
        line = line[:int(order[1]) - 1] + tmp[::-1] + line[int(order[2]) - 1:]
    elif order[0] == "replace":
        line = line[:int(order[1]) - 1] + order[3] + line[int(order[2]) - 1:]

# Fixed version:
line = input()
n = int(input())
for i in range(n):
    order = input().split()
    if order[0] == "print":
        print(line[int(order[1]):int(order[2])+1])
    elif order[0] == "reverse":
        tmp = line[int(order[1]) :int(order[2])+1 ]
        line = line[:int(order[1])] + tmp[::-1] + line[int(order[2])+1:]
    elif order[0] == "replace":
        line = line[:int(order[1])] + order[3] + line[int(order[2])+1:]

# Buggy version:
#!usr/bin/env python3

import sys


def main():
    s = sys.stdin.readline().strip('\n')
    q = int(sys.stdin.readline().strip('\n'))

    for instruction in range(q):
        words = [word for word in sys.stdin.readline().strip('\n').split()]
        print(words)
        if words[0] == 'replace':
            s = s[:int(words[1])] + words[3] + s[int(words[2])+1:]
        elif words[0] == 'reverse':
            s = s[:int(words[1])] \
                    + ''.join(reversed(s[int(words[1]):int(words[2])+1])) \
                    + s[int(words[2])+1:]
        elif words[0] == 'print':
            print(s[int(words[1]):int(words[2])+1])


if __name__ == '__main__':
    main()

# Fixed version:
#!usr/bin/env python3

import sys


def main():
    s = sys.stdin.readline().strip('\n')
    q = int(sys.stdin.readline().strip('\n'))

    for instruction in range(q):
        words = [word for word in sys.stdin.readline().strip('\n').split()]
        if words[0] == 'replace':
            s = s[:int(words[1])] + words[3] + s[int(words[2])+1:]
        elif words[0] == 'reverse':
            s = s[:int(words[1])] \
                    + ''.join(reversed(s[int(words[1]):int(words[2])+1])) \
                    + s[int(words[2])+1:]
        elif words[0] == 'print':
            print(s[int(words[1]):int(words[2])+1])


if __name__ == '__main__':
    main()

# Buggy version:
s = input()
line = int(input())

for i in range(line):
    param = input().split(" ")

    if len(param) == 4: ope, a, b, p = param
    else: ope, a, b = param

    a,b = int(a), int(b)

    if ope == "print":
        print(s[a:b+1])
    elif ope == "reverse":
        rev = s[a:b+1][::-1]
        print(rev)
        s = (s[:a] + rev + s[b+1:])
    elif ope == "replace":
        s = (s[:a] + p + s[b+1:])

# Fixed version:
s = input()
line = int(input())

for i in range(line):
    param = input().split(" ")

    if len(param) == 4: ope, a, b, p = param
    else: ope, a, b = param

    a,b = int(a), int(b)

    if ope == "print":
        print(s[a:b+1])
    elif ope == "reverse":
        rev = s[a:b+1][::-1]
        s = (s[:a] + rev + s[b+1:])
    elif ope == "replace":
        s = (s[:a] + p + s[b+1:])

# Buggy version:
str, q = input(), int(input())
for i in range(q):
    com = input().strip().split()
    if com[0] == 'print':
        print(str[int(com[1]):int(com[2])+1])
    elif com[0] == 'reverse':
        str = list(str)
        str[int(com[1]):int(com[2])+1] = str[int(com[2]):int(com[1])-6:-1]
        str = ''.join(str)
        print(str)
    elif com[0] == 'replace':
        str = str.replace(str[int(com[1]):int(com[2])+1], com[3])
        print(str)

# Fixed version:
str, q = input(), int(input())
for i in range(q):
    com = input().strip().split()
    if com[0] == 'print':
        print(str[int(com[1]):int(com[2])+1])
    elif com[0] == 'reverse':
        str = list(str)
        str[int(com[1]):int(com[2])+1] = str[int(com[2]):int(com[1])-len(str)-1:-1]
        str = ''.join(str)
    elif com[0] == 'replace':
        str = list(str)
        str[int(com[1]):int(com[2])+1] = com[3]
        str = ''.join(str)

# Buggy version:
def main():
    class MyClass:
        def __init__(self):
            self.strings = ""

        def rpl(self, int1, int2, str1):
            self.strings = self.strings[:int1] + str1 + self.strings[int2+1:]
            #self.strings = self.strings.replace(self.strings[int1:int2+1], str1)
            print(self.strings)

        def rvr(self, int1, int2):
            if int1 >= 1:
                revstr = self.strings[int2:int1-1:-1]
            else:
                revstr = self.strings[int2::-1]
            self.strings = self.strings[:int1] + revstr + self.strings[int2+1:]
            print(self.strings)

        def pri(self, int1, int2):
            print(self.strings[int1:int2+1])

    cls = MyClass()
    cls.strings = input()
    n = int(input())
    for _ in range(n):
        li = input().split()
        if li[0] == "replace":
            cls.rpl(int(li[1]), int(li[2]), li[3])
        elif li[0] == "reverse":
            cls.rvr(int(li[1]), int(li[2]))
        elif li[0] == "print":
            cls.pri(int(li[1]), int(li[2]))


if __name__ == "__main__":
    main()

# Fixed version:
def main():
    class MyClass:
        def __init__(self):
            self.strings = ""

        def rpl(self, int1, int2, str1):
            self.strings = self.strings[:int1] + str1 + self.strings[int2+1:]

        def rvr(self, int1, int2):
            if int1 >= 1:
                revstr = self.strings[int2:int1-1:-1]
            else:
                revstr = self.strings[int2::-1]
            self.strings = self.strings[:int1] + revstr + self.strings[int2+1:]

        def pri(self, int1, int2):
            print(self.strings[int1:int2+1])

    cls = MyClass()
    cls.strings = input()
    n = int(input())
    for _ in range(n):
        li = input().split()
        if li[0] == "replace":
            cls.rpl(int(li[1]), int(li[2]), li[3])
        elif li[0] == "reverse":
            cls.rvr(int(li[1]), int(li[2]))
        elif li[0] == "print":
            cls.pri(int(li[1]), int(li[2]))


if __name__ == "__main__":
    main()

# Buggy version:
s = input()
n = int(input())
for i in ragne(n):
    cmd = input().split()
    a,b = map(int,[cmd[1],cmd[2]])
    if cmd[0][0] == 'p':print(s)
    elif cmd[0] =='replace':
        s = s[:a] + cmd[3] + s[b+1:]
    elif cmd[0] =='reverse':
        s = s[:a] + s[a:b+1][::-1] + s[b+1:]

# Fixed version:
s = input()
n = int(input())
for i in range(n):
    cmd = input().split()
    a,b = map(int,[cmd[1],cmd[2]])
    if cmd[0] == 'print':print(s[a:b+1])
    elif cmd[0] == 'reverse':s = s[:a] + s[a:b+1][::-1] + s[b+1:]
    elif cmd[0] == 'replace':s = s[:a] + cmd[3] + s[b+1:]

# Buggy version:
S=input()
m=int(input())
for i in range(m):
    C=input().split()
    a=int(C[1])
    b=int(C[2])+1
    if C[0]=="print":
        print(S[a:b])
    elif C[0]=="reverse":
        S=S[:a]+S[b-len(S)-1:a-len(S)-1:-1]+S[b:]
        print(S)
    elif C[0]=="replace":
        S=S[:a]+C[3]+S[b:]
        print(S)

# Fixed version:
S=input()
m=int(input())
for i in range(m):
    C=input().split()
    a=int(C[1])
    b=int(C[2])+1
    if C[0]=="print":
        print(S[a:b])
    elif C[0]=="reverse":
        S=S[:a]+S[b-len(S)-1:a-len(S)-1:-1]+S[b:]
        
    elif C[0]=="replace":
        S=S[:a]+C[3]+S[b:]

# Buggy version:
str_1=input()
q=int(input())
for _ in range(q):
   lst=list(input().split())
   res = (lst[0])
   a = int(lst[1])
   b = int(lst[2])+1
  
   if res=='print':
    str_1=str_1[a:b]
   elif res=='replace':
    str_1=str_1[:a]+lst[3]+str_1[b:]
   elif res=='reverse':
    str_1=str_1[:a] + str_1[a:b][::-1] + str_1[b:]
print(str_1)

# Fixed version:
str_1=input()
q=int(input())
for _ in range(q):
   lst=list(input().split())
   res = (lst[0])
   a = int(lst[1])
   b = int(lst[2])+1
  
   if res=='print':
     print(str_1[a:b])
   elif res=='replace':
    str_1=str_1[:a]+lst[3]+str_1[b:]
   elif res=='reverse':
    str_1=str_1[:a] + str_1[a:b][::-1] + str_1[b:]

# Buggy version:
moto = input()
num = int(input())

for i in range(num):
    order = input().split()
    if order[0] == "print":
        m,n=int(order[1]),int(order[2])
        print(moto[m:n+1])
    elif order[0] == "reverse":
        m,n=int(order[1]),int(order[2])
        moto = moto[:m]+moto[n:m-1:-1]+moto[n+1:]
    elif order[0] == "replace":
        m,n,l=int(order[1]),int(order[2]),order[3]
        moto = moto[:m]+order[3]+moto[n+1:]

# Fixed version:
moto = input()
num = int(input())

for i in range(num):
    order = input().split()
    if order[0] == "print":
        m,n=int(order[1]),int(order[2])
        print(moto[m:n+1])
    elif order[0] == "reverse":
        m,n=int(order[1]),int(order[2])
        moto = moto[:m]+moto[m:n+1][::-1]+moto[n+1:]
    elif order[0] == "replace":
        m,n,l=int(order[1]),int(order[2]),order[3]
        moto = moto[:m]+order[3]+moto[n+1:]

# Buggy version:
s=input()
for i in range(int(input())):
    sou_com=input().split()
    if sou_com[0]=='print':
        print(s[int(sou_com[1])-1:int(sou_com[2])])
    elif sou_com[0]=='reverse':
        s=s[:int(sou_com[1])-1]\
        +s[int(sou_com[1])-1:int(sou_com[2])][::-1]\
        +s[int(sou_com[2]):]
    elif sou_com[0]=='replace':
        s=s[:int(sou_com[1])-1]\
        +sou_com[3]\
        +s[int(sou_com[2]):]

# Fixed version:
s=input()
for i in range(int(input())):
    sou_com=input().split()
    if sou_com[0]=='print':
        print(s[int(sou_com[1]):int(sou_com[2])+1])
    elif sou_com[0]=='reverse':
        s=s[:int(sou_com[1])]\
        +s[int(sou_com[1]):int(sou_com[2])+1][::-1]\
        +s[int(sou_com[2])+1:]
    elif sou_com[0]=='replace':
        s=s[:int(sou_com[1])]\
        +sou_com[3]\
        +s[int(sou_com[2])+1:]

# Buggy version:
#coding: utf-8

s = input()
q = int(input())
for i in range(q):
    order = input().split(" ")
    if   order[0] == "print":
        print(s[int(order[1]) : int(order[2])+1])
        print(" " + s)
    elif order[0] == "reverse":
        r = s[int(order[1]) : int(order[2])+1]
        print("r: " + r)
        r = r[::-1]
        print("r: " + r)
        s = s[: int(order[1])] + r + s[int(order[2])+1:]
        print(" " + s)

    elif order[0] == "replace":
        s = s[: int(order[1])] + order[3] + s[int(order[2])+1:]
        print(" " + s)



# Fixed version:
#coding: utf-8

s = input()
q = int(input())
for i in range(q):
    order = input().split(" ")
    if   order[0] == "print":
        print(s[int(order[1]) : int(order[2])+1])
    elif order[0] == "reverse":
        r = s[int(order[1]) : int(order[2])+1]
        r = r[::-1]
        s = s[:int(order[1])] + r + s[int(order[2])+1:]
    elif order[0] == "replace":
        s = s[:int(order[1])] + order[3] + s[int(order[2])+1:]

# Buggy version:
s=input()
for _ in range(int(input())):
 a=input().split()
 o=a[0];i=int(a[1]);j=int(a[2])+1
 if'p'==o[0]:print(s[i:j])
 else:
  t=(s[i:j][::-1],a[3])['p'==o[2]]
  s=s[0:i]+t+s[j:]


# Fixed version:
s=input()
for _ in[0]*int(input()):
 a=input().split()
 o=a[0];i=int(a[1]);j=int(a[2])+1
 if'p'==o[0]:print(s[i:j])
 else:
  t=a[3]if'p'==o[2]else s[i:j][::-1]
  s=s[0:i]+t+s[j:]

# Buggy version:

def convert():
    str = input().rstrip()
    n = int(input().rstrip())
    
    for _ in range(n):
        columns = input().rstrip().split()
        order = columns[0]
        a = int(columns[1])
        b = int(columns[2])

        
        if order == 'print':
            print(str[a:b+1])
            
        if order == 'reverse':
            str = str[a:b+1][::-1]
        
        if order == 'replace':        
            p = columns[3]
            str = str[:a] + p + str[b+1:]
if __name__ == '__main__':
    convert()


# Fixed version:
def convert():
    str = input().rstrip()
    n = int(input().rstrip())
    
    for _ in range(n):
        columns = input().rstrip().split()
        order = columns[0]
        a = int(columns[1])
        b = int(columns[2])
        
        if order == 'print':
            print(str[a:b+1])
            
        if order == 'reverse':
            str = str[:a] + str[a:b+1][::-1] + str[b+1:]
        
        if order == 'replace':        
            p = columns[3]
            str = str[:a] + p + str[b+1:] 
if __name__ == '__main__':
    convert()

# Buggy version:
s = input()
n = int(input())

for i in range(n):
    command = input().split()
    if command[0] == 'replace':
        a,b = map(int,command[1:3])
        s = s[:a]+ command[3] + s[b+1:]
    elif command[0] == 'reverse':
        a,b = map(int,command[1:3])
        s[a:b+1] = s[b+1:a]
    elif command[0] == 'print':  
        a,b = map(int,command[1:3])
        print(s[a:b+1])


# Fixed version:
s = input()
n = int(input())

for i in range(n):
    command = input().split()
    if command[0] == 'replace':
        a,b = map(int,command[1:3])
        s = s[:a]+ command[3] + s[b+1:]
    elif command[0] == 'reverse':
        a,b = map(int,command[1:3])
        s = s[0:a] + s[a:b+1][::-1] + s[b+1:]
    elif command[0] == 'print':  
        a,b = map(int,command[1:3])
        print(s[a:b+1])

# Buggy version:
str = input().casefold()
q = int(input())

for i in range(q):
    command = input().split()
    a = int(command[1])
    b = int(command[2])
    if command[0] == "print":
        print(str[a:b+1])
    elif command[0] == 'reverse':
        str = str[a] + str[a:b+1][::-1] + str[b+a:]
    elif command[0] == "replace":
        str = str[:a] +command[3] + str[b+1:]

# Fixed version:
str = input()
q = int(input())

for i in range(q):
    sc = input().split()
    a = int(sc[1])
    b = int(sc[2])
    if sc[0] == 'replace':
        str = str[:a] + sc[3] + str[b+1:]
    elif sc[0] == 'reverse':
        str = str[:a] + str[b::-1][:b-a+1] + str[b+1:]
    elif sc[0] == 'print':
        print(str[a:b+1])

# Buggy version:
s = input()
for i in range(int(input())):
    cmd = input().split()
    a,b = map(int,[cmd[1],cmd[2]])
    if cmd[0] == 'reverse':
        s = s[:b] + s[a:b+1][::-1]+ s[b+1:]
    elif cmd[0] == 'replace':
        s = s[:b] + cmd[3] + s[b+1:]
    else:
        print(s[a:b+1])

# Fixed version:
s = input()
n = int(input())
for i in range(n):
    cmd = input().split()
    a, b = int(cmd[1]), int(cmd[2])
    if cmd[0] == 'print':
        print(s[a:b + 1])
    elif cmd[0] == 'reverse':
        s = s[:a] + s[a:b+1][::-1] + s[b + 1:]
    elif cmd[0] == 'replace':
        s = s[:a] + cmd[3] + s[b + 1:]

# Buggy version:
s = input()
for i in range(int(input())):
    print(s)
    q = input().split()
    op, a, b = q[0], int(q[1]), int(q[2])
    if op == 'print':
        print(s[a : b+1])
    elif op == 'reverse':
        t = s[a : b+1]
        s = s[:a] + t[::-1] + s[b+1:]
    elif op == 'replace':
        s = s[:a] + q[3] + s[b+1:]

# Fixed version:
s=input()
q=int(input())
for i in range(q):
    t=input().split(" ")
    if t[0]=="print":
        a,b=int(t[1]),int(t[2])
        print(s[a:b+1:])
    if t[0]=="reverse":
        a,b=int(t[1]),int(t[2])
        s=s[:a:]+s[a:b+1:][::-1]+s[b+1::]
    if t[0]=="replace":
        a,b=int(t[1]),int(t[2])
        x=t[3]
        s=s[:a:]+x+s[b+1::]

# Buggy version:
s=list(input())
n=int(input())
for i in range(n):
	l=input().split()
	if l[0]=="replace":
		a=int(l[1])
		b=int(l[2])
		s[a:b+1]=list(l[3])
	elif l[0]=="reverse":
		a=int(l[1])
		b=int(l[2])
		s[a:b+1]=s[a:b+1:-1]
	else:
		a=int(l[1])
		b=int(l[2])
		print("".join(s[a:b+1]))

# Fixed version:
s=list(input())
n=int(input())
for i in range(n):
    a=input().split()
    if a[0]=='print':print(''.join(s[int(a[1]):int(a[2])+1]))
    elif a[0]=='replace':s[int(a[1]):int(a[2])+1]=a[3]
    else:s[int(a[1]):int(a[2])+1]=s[int(a[1]):int(a[2])+1][::-1]

# Buggy version:
s = input()
q = int(input())
for i in range(q):
    command = input().split()
    a, b = int(command[1]), int(command[2]) + 1
    if command[0] == "print":
        print(s[a:b])
    elif command[0] == "reverse":
        s = s[:a] + s[a:b:-1] + s[b:]
    elif command[0] == "replace":
        s = s[:a] + command[3] + s[b:]

# Fixed version:
s=input()
q=int(input())
for i in range(q):
    l = input().split()
    a,b = int(l[1]),int(l[2])
    if l[0]=="print":
        print(s[a:b+1])
    elif l[0]=="reverse":
        s1=s[a:b+1]
        s=s[:a]+s1[::-1]+s[b+1:]
    elif l[0]=="replace":
        s=s[:a]+l[3]+s[b+1:]

# Buggy version:
str=input()
n=int(input())
for i in range(n):
    s=input().split()
    a=int(s[1])
    b=int(s[2])
    if s[0] == 'replace':
        str=str[:a]+s[3]+str[b:]
    elif s[0] == 'reverse':
        str=str[:a]+str[a:b][::-1]+str[b:]
    else:
        print(str[a:b])

# Fixed version:
s = input()
n = int(input())
for i in range(n):
  q = input().split()
  a, b = int(q[1]), int(q[2])
  if q[0]=="print":
    print(s[a:b+1])
  elif q[0]=="reverse":
    if a==0:
      s = s[b::-1]+s[b+1:]
    else:
      s = s[:a]+s[b:a-1:-1]+s[b+1:]
  elif q[0]=="replace":
    s = s[:a]+q[3]+s[b+1:]