Problem:
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. Input 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. Output For each print command, print a string in a line. Constraints  $1 \leq $ length of $str \leq 1000$  $1 \leq q \leq 100$  $0 \leq a \leq b < $ length of $str$  for replace command, $b - a + 1 = $ length of $p$  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

Solution (Python):
o = input()
for _ in range(int(input())):
    s = input().split()
    a, b = map(int, s[1:3]); b+=1
    if s[0][2]=='i': print(o[a:b])
    elif s[0][2]=='p': o=o[:a]+s[3]+o[b:]
    else: o=o[:a]+o[a:b][::-1]+o[b:]

Solution (Python):
line = input()
n = int(input())

for _ in range(n):
    x = list(map(str, input().split()))
    a, b = int(x[1]), int(x[2])
    if x[0] == "print":
        print(line[a:b+1])
    elif x[0] == "reverse":
        line = line[:a] + line[a:b+1][::-1] + line[b+1:]
    else:
        line = line[:a] + x[3] + line[b+1:]

Solution (Python):
t = list(input())
n = int(input())
for i in range(n):
    s = input().split()
    if s[0] == "print":
        print("".join(t[int(s[1]):int(s[2])+1]))
    elif s[0] == "reverse":
        for j in range(((int(s[2])-int(s[1]))//2)+((int(s[2])-int(s[1]))%2)):
             temp = t[int(s[1])+j]
             t[int(s[1])+j] = t[int(s[2])-j]
             t[int(s[2])-j] = temp
    elif s[0] == "replace":
        for k in range(len(s[3])):
            t[int(s[1])+k] = s[3][k]

Solution (Python):
k = [x for x in input()]
n = int(input())
for _ in range(n):
    command = [_ for _ in input().split()]
    if command[0] == "replace":
        del k[int(command[1]):int(command[2])+1]
        for i in range(len(command[3])):
            k.insert(int(command[1]),command[3][len(command[3])-i-1])
    elif command[0] == "reverse":
        b = k[int(command[1]):int(command[2])+1]
        del k[int(command[1]):int(command[2])+1]
        for i in range(len(b)):
            k.insert(int(command[1]),b[i])
    elif command[0] == "print":
        a = k[:]
        for u in range(int(command[1]),int(command[2])+1):
            print(a[u],end ="")
        else:
            print()

Solution (Python):
str = input()
for _ in range(int(input())):
  odr = input().split()
  a = int(odr[1])
  b = int(odr[2]) + 1
  if odr[0] == 'replace':
    str = str[:a] + odr[3] + str[b:]
  elif odr[0] == 'reverse':
    str = str[:a] + str[a:b][::-1] + str[b:]
  else:
    print(str[a:b])

Solution (Python):
string = input()
q = int(input())

for i in range(q):
  order = input().split()
  if order[0] == "print":
    print(string[int(order[1]):int(order[2])+1])
  elif order[0] == "reverse":
    rev_b = int(order[1])
    rev_e = int(order[2])
    if rev_b == 0:
      string = string[rev_e::-1] + string[rev_e+1:]
    else:
      string = string[:rev_b] + string[rev_e:rev_b-1:-1] + string[rev_e+1:]
  elif order[0] == "replace":
    rep_b = int(order[1])
    rep_e = int(order[2])
    string = string[:rep_b] + order[3] + string[rep_e+1:]

Solution (Python):
s = input()
n = int(input())
for i in range(n):
    t = input().split()
    a = int(t[1])
    b = int(t[2])
    if t[0] == "print":
        print(s[a:b+1])
    elif t[0] =="replace":
        s = s[0:a]+t[3]+s[b+1:len(s)]
    elif t[0] == "reverse":
        u = s[a:b+1]
        s = s[0:a]+u[::-1]+s[b+1:len(s)]

Solution (Python):
words=str(input())
n=int(input())
for i in range(n):
    order=str(input())
    order_s=order.split()
    if order_s[0]=="print":
        print(words[int(order_s[1]):int(order_s[2])+1])
    if order_s[0]=="reverse":
        w_k=words[int(order_s[1]):int(order_s[2])+1]
        words=words.replace(w_k, w_k[::-1])
    if order_s[0]=="replace":
        k=0
        s_l=list(words)
        for j in range(int(order_s[1]),int(order_s[2])+1):
            s_l[j]=order_s[3][k]
            k+=1
        words="".join(s_l)

Solution (Python):
s = input()
N = int(input())

printList = []

for i in range(N):
    c = list(map(str, input().split()))
    start = int(c[1])
    end = int(c[2])+1
    
    if c[0] == "print":
        printList.append(s[start:end])
    elif c[0] == "replace":
        r = c[3]
        s = s[:start] + r + s[end:]
    elif c[0] == "reverse":
        r = s[start:end]
        sr = r[::-1]
        s = s[:start] + sr + s[end:]
    
for p in printList:
    print(p)

Solution (Python):
import copy
function = 0
start = 1
end = 2
replaceStr = 3
reverseStart=0
reverseEnd=0
str = 3
reverseTarget=[]
reversedStr=[]
inStr = list(input())
outStr = copy.deepcopy(inStr)
commandNumber = int(input())
for currentNumber in range(commandNumber):
    command = input().split(" ") 
    if command[function] == "print":
        printStart = int(command[start])
        printEnd = int(command[end])
        print("".join(outStr[printStart:printEnd+1]))
    
    elif command[function] == "reverse":
        reverseStart = int(command[start])
        reverseEnd = int(command[end])
        reverseTarget.append(outStr[reverseStart:reverseEnd+1])
        reversedStr = reverseTarget[-1][::-1]
        outStr[reverseStart:reverseEnd+1] = reversedStr
    
    elif command[function] == "replace":
        replaceStart = int(command[start])
        replaceEnd = int(command[end])
        replaceStr = list(command[str])
        outStr[replaceStart:replaceEnd+1] = replaceStr

Solution (Python):

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

Solution (Python):
word = input()
nums = int(input())

for _ in range(nums):
    row = input().split()
    if row[0] == 'replace':
        s, e, st = int(row[1]), int(row[2]), row[3]
        word = word[:s] + st + word[e+1:]
    elif row[0] == 'reverse':
        s, e = int(row[1]), int(row[2])
        word = word[:s] + ''.join(reversed(word[s:e+1])) + word[e+1:]
    elif row[0] == 'print':
        s, e = int(row[1]), int(row[2])
        print(word[s:e+1])

Solution (Python):
s = input()
q = int(input())
for line in range(q):
    op = input().split()
    st, ed = map(int, op[1:3])
    if op[0] == 'print':
        print(s[st:ed + 1])
    elif op[0] == 'reverse':
        if st == 0: 
            s = s[ed:0:-1] + s[0] + s[ed + 1:]
        else: 
            s = s[:st] + s[ed: st-1 :-1] + s[ed + 1:]
    elif op[0] == 'replace':
        s = s[:st] + op[3] + s[ed + 1:]

Solution (Python):
s = list(input())

for i in range(int(input())):
    order, a, b, *c = input().split()
    a = int(a)
    b = int(b)
    if order == "print":
        print(*s[a:b+1], sep='')
    if order == "reverse":
        s[a:b+1] = reversed(s[a:b+1])
    if order == "replace":
        s[a:b+1] = c[0]

Solution (Python):
string = input()
n = int(input())
for x in range(n):
    command = tuple(map(str, input().split()))
    if command[0] == "print":
        a = int(command[1])
        b = int(command[2]) + 1
        print(string[a:b])
    elif command[0] == "reverse":
        a = int(command[1])
        b = int(command[2]) + 1
        old = string[a:b]
        new = ""
        for y in old:
            new = y + new
        string = string[:a] + new + string[b:]
    else:
        a = int(command[1])
        b = int(command[2]) + 1
        p = command[3]
        string = string[:a] + p + string[b:]

Solution (Python):
word = input()
n = int(input())
for i in range(n):
    command = list(input().split())
    temp = ""
    if command[0] == "print":
        print(word[int(command[1]):int(command[2])+1])
    elif command[0] == "reverse":
        temp += word[:int(command[1])]
        for i in range(int(command[2]), int(command[1])-1, -1):
            temp += word[i]
        temp += word[int(command[2])+1:]
        word = temp
    else:
        temp += word[:int(command[1])]
        temp += command[3]
        temp += word[int(command[2])+1:]
        word = temp

Solution (Python):
s = input()
num = int(input())

for i in range(num):
        orderList = input().split()
        a = int(orderList[1])
        b = int(orderList[2])
        if orderList[0] == "replace":
                s = s[:a] + orderList[3] + s[b + 1:]
        elif orderList[0] == "reverse":
                s = s[:a] + s[a:b + 1][::-1] + s[b + 1:]
        else:
                print(s[a:b + 1])

Solution (Python):
W = list(input())
N = int(input())

for i in range(N):
    command,a,b,*c = input().split()
    a= int(a) ; b= int(b)
    if command == 'print':
        print(*W[a:b+1],sep='')
    elif command == 'reverse':
        W[a:b+1] = reversed(W[a:b+1])
    else:
        W[a:b+1] = c[0]

Solution (Python):
text = input()
n = int(input())
for _ in range(n):
    do = input().split()
    m = int(do[1])
    s = int(do[2])
    if do[0] == "print":
        print(text[m:s + 1])
    elif do[0] == "reverse":
        text = text[0:m] + text[m:s+1][::-1] + text[s + 1:]
    else:
        text = text[0:m] + do[3] + text[s + 1:]

Solution (Python):
string = input()
for i in range(int(input())):
    process = input().split()
    num_a = int(process[1])
    num_b = int(process[2])
    if process[0] == 'replace':
        string = string[:num_a] + process[3] + string[num_b+1:]
    elif process[0] == 'reverse':
        string = string[:num_a] + string[num_a:num_b+1][::-1] + string[num_b+1:]
    elif process[0] == 'print':
        print(string[num_a:num_b+1])

Solution (Python):
s = input()
n = int(input())
for i in range(n):
	t = input().split()
	a = int(t[1])
	b = int(t[2])
	if t[0] == "print":
		print(s[a:b + 1])
	elif t[0] == "replace":
		s = s[0 : a] + t[3] + s[b + 1 : len(s)]
	elif t[0] == "reverse":
		u = s[a : b + 1]
		s = s[0 : a] + u[ : : -1] + s[b + 1 : len(s)]

Solution (Python):
str = input()
for _ in range(int(input())):
    a = input().split()
    if a[0] == "print":
        print(str[int(a[1]):int(a[2]) + 1])
    elif a[0] == "replace":
        str = str[:int(a[1])] + a[3] + str[int(a[2]) + 1:]
    else:
        str = str[:int(a[1])] + str[int(a[1]):int(a[2]) + 1][::-1] + str[int(a[2]) + 1:]

Solution (Python):
s = input()



n = int(input())


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

Solution (Python):
def _print(a,b,s):
    print(s[a:b+1])
def _reverse(a,b,s):
    return s[:a]+s[a:b+1][::-1]+s[b+1:]
def _replace(a,b,p,s):
    return s[:a]+p+s[b+1:]

s = input()
n = int(input())
for i in range(n):
    c = input().split()
    if c[0] == "print":
        _print(int(c[1]),int(c[2]),s)
    elif c[0] == "reverse":
        s = _reverse(int(c[1]),int(c[2]),s)
    else:
        s = _replace(int(c[1]),int(c[2]),c[3],s)

Solution (Python):
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]

Solution (Python):
strlist = list(input())
q = int(input())
for n in range(q):
    coms = input().split()
    if coms[0] == 'print':
        print(''.join(strlist[int(coms[1]):int(coms[2])+1]))
    elif coms[0] == 'reverse':
        
        
        new = list(reversed(strlist[int(coms[1]):int(coms[2])+1]))
        
        strlist[int(coms[1]):int(coms[2])+1] = new
        
    elif coms[0] == 'replace':
        strlist[int(coms[1]):int(coms[2])+1] = list(coms[3])[0:]

Solution (Python):
import sys


def print_str(str, a, b):
    print(str[a:b+1])


def reverse_str(str, a, b):
    return str[:a] + str[a:b+1][::-1] + str[b+1:]


def replace_str(str, a, b, p):
    return str[:a] + p + str[b+1:]


str = sys.stdin.readline().strip()
num_commands = int(sys.stdin.readline())

for _ in range(num_commands):
    command, *args = sys.stdin.readline().strip().split()
    if command == 'print':
        print_str(str, int(args[0]), int(args[1]))
    elif command == 'reverse':
        str = reverse_str(str, int(args[0]), int(args[1]))
    elif command == 'replace':
        str = replace_str(str, int(args[0]), int(args[1]), args[2])

Solution (Python):
s=list(input())

for i in range(int(input())):
    cmd,a,b,*c=input().split()
    a,b=int(a),int(b)
    
    if cmd=="print":
        print(*s[a:b+1],sep="")
    elif cmd=="reverse":
        s[a:b+1]=s[a:b+1][::-1]
    else:
        s[a:b+1]=c[0]

Solution (Python):
str = input()
q = int(input())

for _ in range(q):
    line = input().split()
    c = line[0]
    a = int(line[1])
    b = int(line[2]) + 1

    if c == 'replace':
        str = str[:a] + line[3] + str[b:]
    elif c == 'reverse':
        str = str[:a] + str[a:b][::-1] + str[b:]
    else:
        print(str[a:b])

Solution (Python):
text = input()
n = int(input())
for i in range(n):
    cmd, *arg = input().split()
    arg0, arg1 = int(arg[0]), int(arg[1])
    if cmd == 'print':
        print(text[arg0:arg1+1])
    elif cmd == 'reverse':
        text = text[:arg0] + text[arg0:arg1+1][::-1] + text[arg1+1:]
    else: 
        text = text[:arg0] + arg[2] + text[arg1+1:]

Solution (Python):
str = input()
q = int(input())

for _ in range(q):
    line = input().split()
    c = line[0]
    a = int(line[1])
    b = int(line[2]) + 1

    if c == 'replace':
        str = str[:a] + line[3] + str[b:]
    elif c == 'reverse':
        str = str[:a] + str[a:b][::-1] + str[b:]
    else:
        print(str[a:b])

Solution (Python):
def hyouji(moji,a,b):
    for j in range(a,b):
        print(moji[j],end="")
    print()

def gyakujun(moji,a,b):
    moji1=[moji[i] for i in range(a,b)]
    moji1.reverse()
    for i in range(a,b):
        moji[i]=moji1[i-a]
    return moji
    
def replace(moji,a,b,p):
    for i in range(a,b):
        moji[i]=p[i-a]
    return moji

nyuryoku=input()
moji=[]

for i in nyuryoku:
    moji.append(i)

kaisu=int(input())

for j in range(kaisu):
    command=list(map(str,input().split()))
    p=[]
    meirei=command[0]
    a=int(command[1])
    b=int(command[2])+1
    if len(command)==4:
        for i in command[3]:
            p.append(i)
    if meirei=="print":
        hyouji(moji,a,b)
    elif meirei=="reverse":
        gyakujun(moji,a,b)
    elif meirei=="replace":
        replace(moji,a,b,p)

Solution (Python):
w = str(input())
n = int(input())
while ( n > 0 ):
    n = n -1
    l  =  list(map(str,input().split()))
    if (l[0] == "print" ):
        print (w[int(l[1]):int(l[2])+1])
    elif(l[0] == "replace"):
        p1 = int(l[1])
        p2 = int(l[2])
        w = w[:p1] + l[3] + w[p2+1:]
    elif(l[0] == "reverse"):
        p1 = int(l[1])
        p2 = int(l[2])
        t1 = w[:p1]
        t2 = w[p1:p2+1]
        t3 = w[p2+1:]
        w = t1 + t2[::-1] + t3

Solution (Python):
s=input()
for _ in range(int(input())):
    o=input().split()
    a,b=map(int,o[1:3]);b+=1
    c=o[0][2]
    if c=='p':s=s[:a]+o[3]+s[b:]
    elif c=='i':print(s[a:b])
    elif c=='v':s=s[:a]+s[a:b][::-1]+s[b:]

Solution (Python):
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:]

Solution (Python):
s = input()
q = int(input())

printlist = []

for _ in range(q):
    c = list(map(str, input().split()))
    start = int(c[1])
    end = int(c[2]) + 1

    if c[0] == "print":
        printlist.append(s[start:end])
    elif c[0] == "reverse":
        r = s[start:end]
        sr = r[::-1]
        s = s[:start] + sr + s[end:]
    elif c[0] == "replace":
        r = c[3]
        s = s[:start] + r + s[end:]

for p in printlist:
    print(p)

Solution (Python):
str_chr = input()
n = int(input())
order = []

for _ in range(n):
    order = list(input().split())
    a,b = int(order[1]),int(order[2])+1
    if   order[0] == 'replace':
        str_chr = str_chr[:a]+order[3]+str_chr[b:]
    elif order[0] == 'reverse':
        str_chr = str_chr[:a]+str_chr[a:b][::-1]+str_chr[b:]
    elif order[0] == 'print':
        print(str_chr[a:b])

Solution (Python):
def merge(A,i,B):
    A_1=A[0:i]
    A_2=A[i:len(A)]
    return A_1 +B + A_2


str = input()
str =list(str)
n=int(input())
for i in range(0,n):
    order=input().split()
    order[1]=int(order[1])
    order[2]=int(order[2])
    if(order[0]=="print"):
        print("".join(str[order[1]:order[2]+1]))
    elif(order[0]=="replace"):
        del str[order[1]:order[2]+1]
        str=merge(str,order[1],list(order[3]))
    elif(order[0]=="reverse"):
        key=str[order[1]:order[2]+1]
        key.reverse()
        del str[order[1]:order[2]+1]
        str=merge(str,order[1],key)

Solution (Python):
s = input()
for i in range(int(input())):
    lst = input().split()
    a,b = map(int, lst[1:3])
    if(lst[0] == "print"): print(s[a:b+1])
    elif(lst[0] == "reverse"): s = s[:a] + s[a:b+1][::-1] + s[b+1:]
    else: s = s[:a] + lst[-1] + s[b+1:]

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

Solution (Python):
str = input()
n = int(input())

for i in range(n):
	line = input().split()
	com = line[0]
	x = int(line[1])
	y = int(line[2])
	
	if com == 'replace':
		str = str[:x]+line[3]+str[y+1:]
	elif com == 'reverse':
		str = str[:x]+str[x:y+1][::-1]+str[y+1:]
	elif com == 'print':
		print(str[x:y+1])

Solution (Python):
s = input()
command_n = int(input())
for i in range(command_n):
    command, a, *b = [int(i) if i.isdigit() else i for i in input().split() ]
    
    if command == "print":
        b = b[0]
        print(s[a:b+1])
    if command == "reverse":
        b = b[0]
        s_ab = s[a:b+1]
        s = s.replace(s_ab, s_ab[::-1])
    if command == "replace":
        b, p = b[0], b[1]
        L_s = list(s)
        L_s[a:b+1] = p
        s = "".join(L_s)

Solution (Python):
s = str(input())
n = int(input())
m = []

for i in range(n):
    m = list(input().split())
    i1 = int(m[1])
    i2 = int(m[2])+1
    if m[0] == "replace":
        s = s[0:i1] + m[3] + s[i2::]
        
    elif m[0] == "reverse":
        sr = s[i1:i2]
        sr = sr[::-1]
        s = s[0:i1] + sr + s[i2::]
        
    elif m[0] == "print":
        print(s[i1:i2])

Solution (Python):
s = input()
for _ in range(int(input())):
    cmds = input().split()
    if cmds[0]=='print':
        a, b = map(int, cmds[1:])
        print(s[a:b+1])
    elif cmds[0]=='reverse':
        a, b = map(int, cmds[1:])
        s = s[:a] + s[b:-len(s)+a-1:-1] + s[b+1:]
    elif cmds[0]=='replace':
        a, b = map(int, cmds[1:3])
        p = cmds[3]
        s = s[:a] + p + s[b+1:]

Solution (Python):
str_in = input()
str_len = len(str_in)
n = int(input())

for i in range(0, n):
    c = input().split()
    if (c[0] == 'print'):
        print(str_in[int(c[1]) : int(c[2]) + 1])
    elif (c[0] == 'reverse'):
        temp = ''
        for l in str_in[int(c[1]) : int(c[2]) + 1]:
            temp = l + temp
        str_in = str_in[0 : int(c[1])] + temp + str_in[int(c[2]) +1 : str_len]
    elif (c[0] == 'replace'):
        str_in = str_in[0 : int(c[1])] + c[3] + str_in[int(c[2]) +1 : str_len]

Solution (Python):
line = input()
n = int(input())

for _ in range(n):
    x = list(map(str, input().split()))
    a, b = int(x[1]), int(x[2])
    if x[0] == "print":
        print(line[a:b+1])
    elif x[0] == "reverse":
        line = line[:a] + line[a:b+1][::-1] + line[b+1:]
    else:
        line = line[:a] + x[3] + line[b+1:]

Solution (Python):
string = input()
q = int(input())
for _ in range(q):
    command = input().split()
    a, b = int(command[1]), int(command[2])
    if command[0] == "replace":
        string = string[:a] + command[3] + string[b+1:]
    elif command[0] == "reverse":
        string = string[:a] + string[a:b+1][::-1] + string[b+1:]
    elif command[0] == "print":
        print(string[a:b+1])

Solution (Python):
from enum import Enum
import sys

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


line = input()
num_query = int(input())

for loop in range(num_query):

    input_str = list(input().split())

    if input_str[0] == 'replace':
        left = int(input_str[1])
        right = int(input_str[2])
        right += 1
        line = line[:left] + input_str[3] + line[right:]

    elif input_str[0] == 'reverse':
        left = int(input_str[1])
        right = int(input_str[2])
        right += 1
        line = line[:left] + line[left:right][::-1] + line[right:]

    else: 
        left = int(input_str[1])
        right = int(input_str[2])
        right += 1
        for i in range(left,right):
            print(line[i],end = "")
        print()

Solution (Python):
s = input()
n = int(input())
for i in range(n):
    q = input().split()
    if q[0] == "print":
        print(s[int(q[1]) : int(q[2]) + 1 ])
    elif q[0] == "reverse":
        sa = s[int(q[1]):int(q[2]) + 1]
        sa = sa[::-1]
        s = s[:int(q[1])] + sa + s[int(q[2]) + 1:]
    else:
        s = s[:int(q[1])] + q[3] + s[int(q[2]) + 1:]

Solution (Python):
N=input()
n=int(input())
for i in range(n):
    s=input()
    s=s.rstrip().split(" ")
    if s[0]=="replace":
        N=N[:int(s[1])]+s[3]+N[int(s[2])+1:]
    elif s[0]=="reverse":
        a=""
        for j in range(int(s[2])-int(s[1])+1):
            a=a+N[int(s[2])-j]
        N=N[:int(s[1])]+a+N[int(s[2])+1:]
    elif s[0]=="print":
        print(N[int(s[1]):int(s[2])+1])

Solution (Python):

st = input()
q = int(input())

for _ in range(q):
    rule = list(map(str,input().split()))
    a,b = int(rule[1]), int(rule[2])
    if rule[0] == "print":
        print(st[a:b+1])
    elif rule[0] == "reverse":
        st = st[:a] + st[a:b+1][::-1] + st[b+1:]
    else:
        st = st[:a] + rule[3] + st[b+1:]

Solution (Python):

origin = input()
loops = int(input())

for _ in range(loops):
    command = input().split()
    start = int(command[1])
    end = int(command[2]) + 1

    
    if 'replace' in command:
        rep_str = command[3]
        origin = list(origin)
        for i, index in enumerate(range(start, end)):
            origin[index] = rep_str[i]
        origin = ''.join(origin)

    elif 'reverse' in command:
        rev_str = origin[start:end][::-1]
        origin = origin.replace(origin[start:end], rev_str)

    else:
        print(origin[start:end])

Solution (Python):
def doIt(t, c):
	c = c.split()
	t = list(t)
	if c[0] == 'replace':
		j = 0
		temp = [x for x in c[3]]
		for i in range(int(c[1]), int(c[2]) + 1):
			t[i] = temp[j]
			j += 1
	elif c[0] == 'reverse':
		temp = t[int(c[1]):int(c[2]) + 1]
		j = len(temp) - 1
		for i in range(int(c[1]), int(c[2]) + 1):
			t[i] = temp[j]
			j -= 1
	else:
		print(''.join(t[int(c[1]):int(c[2])+1]))
	return ''.join(t)

text = input()
n = int(input())
while n > 0:
	text = doIt(text, input())
	n -= 1

Solution (Python):
str = input()
q = int(input())

for _ in range(q):
    line = input().split()
    c = line[0]
    a = int(line[1])
    b = int(line[2]) + 1

    if c == 'replace':
        str = str[:a] + line[3] + str[b:]
    elif c == 'reverse':
        str = str[:a] + str[a:b][::-1] + str[b:]
    else:
        print(str[a:b])

Solution (Python):


if __name__ == '__main__':
    s = raw_input()
    q = int(raw_input())

    for _ in range(q):
        op = raw_input().split()
        a, b = map(int, op[1:3])
        p = ''.join(op[3:])
        op = op[0]

        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:]

Solution (Python):
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:]

Solution (Python):
S = [s for s in input()]
p = int(input())
for _ in range(p):
	sy = input().split(' ')
	op = sy[0]
	a = int(sy[1])
	b = int(sy[2])
	if op == 'print':
		sh = ''
		for i in range(a,b+1): sh += S[i]
		print(sh)
	elif op == 'reverse':
		pick = []
		for i in range(a,b+1): pick.append(S.pop(a))
		for i,r in enumerate(reversed(pick)): S.insert(a+i, r)
	elif op == 'replace':
		q = [s for s in sy[3]]
		for i,s in enumerate(q):
			S.pop(a+i)
			S.insert(a+i, s)