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):
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):
S = input()
N = int(input())
for i in range(N):
    operate = input().split()
    if operate[0] == "replace":
        n = int(operate[1])
        m = int(operate[2])+1
        left_str = S[:n]
        right_str = S[m:]
        center_str = operate[3]
        S = left_str + center_str + right_str
    elif operate[0] == "reverse":
        n = int(operate[1])
        m = int(operate[2])+1
        left_str = S[:n]
        center_str = S[n:m]
        right_str = S[m:]
        center_str = center_str[::-1]
        S = left_str + center_str + right_str
    elif operate[0] == "print":
        n = int(operate[1])
        m = int(operate[2])+1
        left_str = S[:n]
        center_str = S[n:m]
        right_str = S[m:]
        print(center_str)

Solution (Python):
s = input()

q = int(input())
query = []

for _ in range(q):
    query = input().split()
    if query[0] == 'replace':
        a, b = map(int, query[1:3])
        s = s[:a] + query[3] + s[b+1:]
    elif query[0] == 'reverse':
        a, b = map(int, query[1:3])
        r = s[b:a-1:-1] if a != 0 else s[b::-1]
        s = s[:a] + r + s[b+1:]
    elif query[0] == 'print':
        a, b = map(int, query[1:3])
        print(s[a:b+1])

Solution (Python):
string = input()
num = int(input())
o = 0
for _ in range(num):
    source = input().split(' ')
    if source[0] == 'print':
        print(string[int(source[1]):int(source[2]) + 1])
    elif source[0] == 'replace':
        string = string[:int(source[1])] + source[3] + string[int(source[2]) + 1:]
    else:
        string = string[:int(source[1])] + string[int(source[1]):int(source[2]) + 1 ][::-1] + string[int(source[2]) + 1:]

Solution (Python):
s = input()
q = int(input())
insts = [input().split() for _ in range(q)]

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

Solution (Python):
s = input()
n = int(input())
for i in range(n):
    l = input().split()
    if l[0] == 'replace':
        s = s[:int(l[1])] + str(l[3]) + s[int(l[2]) + 1:]
    elif l[0] == 'reverse':
        s = s[:int(l[1])] + s[int(l[1]):int(l[2])+1][::-1] + s[int(l[2]) + 1:]
    elif l[0] == 'print':
        print(s[int(l[1]):int(l[2]) + 1])

Solution (Python):
a = input()
for i in range(int(input())):
    b = list(input().split(' '))
    if 'print' in b:
        f = int(b[1])
        s = int(b[2])
        print(a[f:s+1])
    elif 'reverse' in b:
        f = int(b[1])
        s = int(b[2])
        a = a[:f] + a[f:s+1:][::-1] + a[s+1:]
    else:
        f = int(b[1])
        s = int(b[2])
        a = a[:f] + b[3] + a[s+1:]

Solution (Python):
"""
print a b: strの a 文字目から b 文字目までを出力する。
reverse a b: strの a 文字目から b 文字目までを逆順にする。
replace a b p: st の a 文字目から b 文字目までを p に置き換える
"""
s = str(input())
n_order = int(input())


for _ in range(n_order):
    list_order = [i for i in input().split(" ")]
    order = list_order[0]
    a = int(list_order[1])
    b = int(list_order[2])

    if order == 'print':
        s_a2b = s[a : b + 1]
        print(s_a2b)
    elif order == 'reverse':
        s_a2b = s[a : b + 1]
        s_a2b_rev = s_a2b[::-1]
        s = s[:a] + s_a2b_rev + s[b + 1:]
        
    elif order == 'replace':
        p = str(list_order[3])
        s = s[:a] + p + s[b + 1:]
        
    else:
        print("error")

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

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

s = list(s)

for i in range(n):
  arv = [a for a in input().split()]

  if (arv[0] == "reverse"):
    reverse_s = s[int(arv[1]) : int(arv[2])+1]
    reverse_s.reverse()
    s[int(arv[1]) : int(arv[2])+1]= reverse_s
  
  if (arv[0] == "replace"):
    s[int(arv[1]) : int(arv[2])+1] = list(arv[3])
        
  if (arv[0] == "print"):
    print("".join(s[int(arv[1]):int(arv[2])+1]))

Solution (Python):
S = list(input())
q = int(input())
for i in range(q):
    cmd, a, b, *c = input().split()
    a = int(a)
    b = int(b)
    if cmd == "replace":
        S[a:b+1] = c[0]
    elif cmd == "reverse":
        S[a:b+1] = reversed(S[a:b+1])
    else:
        print(*S[a:b+1], sep='')

Solution (Python):
word = input()
n = int(input())
for _ in range(n):
    meirei = input().split()
    if meirei[0] == "print":
        print(word[int(meirei[1]):int(meirei[2])+1])
    elif meirei[0] == "reverse":
        word = word[:int(meirei[1])] + word[int(meirei[1]):int(meirei[2])+1][::-1] + word[int(meirei[2])+1:]
    elif meirei[0] == "replace":
        word = word[:int(meirei[1])] + meirei[3] + word[int(meirei[2])+1:]

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

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

Solution (Python):
temp = input()
n = int(input())
for _ in range(n):
    order,a,b,*value = input().split()
    a = int(a)
    b = int(b)

    if order == "print":
        print(temp[a:b+1])
    elif order == "reverse":
        rev = temp[a:b+1]
        temp = temp[:a] + rev[::-1] + temp[b+1:]
    else:
        temp = temp[:a] + value[0] + temp[b+1:]

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

Solution (Python):
import sys
S = input()
N = int(input())
for i in range(N):
  a = sys.stdin.readline().split()
  if a[0] == "replace":
    S = S[:int(a[1])] + a[3] + S[int(a[2])+1:]
  elif a[0] == "reverse":
    X =  S[int(a[1]):int(a[2])+1]
    X = X[::-1]
    S = S[:int(a[1])] + X +S[int(a[2])+1:]
  elif a[0] == "print":
    print(S[int(a[1]):int(a[2])+1])

Solution (Python):
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):
text=input()
n=int(input())
for i in range(n):
    order=input().split()
    a,b=map(int,order[1:3])
    if order[0]=="print":
        print(text[a:b+1])
    elif order[0]=="reverse":
        re_text=text[a:b+1]
        text=text[:a]+re_text[::-1]+text[b+1:]
    else :
        text=text[:a]+order[3]+text[b+1:]

Solution (Python):
s = input()
n = int(input())
for _ in range(n):
    l = input().split()
    i_1 = int(l[1])
    i_2 = int(l[2]) + 1
    if l[0] == 'replace':
        s = s[:i_1] + l[3] + s[i_2:]
    elif l[0] == 'reverse':
        s = s[:i_1] + s[i_1:i_2][::-1] + s[i_2:]
    elif l[0] == 'print':
        print(s[i_1:i_2])

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

for _ in range(q):
    od = list(map(str, input().split()))

    if od[0] == "print":
        print(word[int(od[1]): int(od[2]) + 1])

    elif od[0] == "reverse":
        if int(od[1]) == 0:
            word = "{}{}{}".format(word[: int(od[1])], word[int(
                od[2])::-1], word[int(od[2]) + 1:])
        else:
            word = "{}{}{}".format(word[: int(od[1])], word[int(
                od[2]): int(od[1]) - 1:-1], word[int(od[2]) + 1:])

    elif od[0] == "replace":
        word = "{}{}{}".format(
            word[: int(od[1])], od[3], word[int(od[2]) + 1:])

Solution (Python):
S = input()
q = int(input())
for i in range(q):
    cmd = input().split()
    a = int(cmd[1])
    b = int(cmd[2])
    
    if cmd[0] == "print":
        print(S[a:b+1])
        
    elif cmd[0] == "replace":
        S = S[0:a] + cmd[3] + S[b+1:len(S)]
    
    elif cmd[0] == "reverse":
        r = S[a:b+1]
        S = S[0:a] + r[::-1] + S[b+1:len(S)]

Solution (Python):

from sys import stdin







def mreplace(s, e, rep_str,v_str):
  replaced_str = v_str[:s] + rep_str + v_str[e + 1:]
  
  return replaced_str

def mreverse(s, e, v_str):
  reversed_str = v_str[:s]+ v_str[s:e+1][::-1]+v_str[e+1:]
  
  return reversed_str


def mprint(s, e, v_str):
  print(v_str[s:e+1])


STR = stdin.readline().rstrip()
q = int(stdin.readline().rstrip())
for i in range(q):
  A = list(stdin.readline().split())
  if A[0] == "print":
    mprint(int(A[1]),int( A[2]), STR)
  elif A[0] == "replace":
    STR = mreplace(int(A[1]), int(A[2]), A[3], STR)
  elif A[0] == "reverse":
    STR = mreverse(int(A[1]), int(A[2]), STR)

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

for i in range(n):
    x = list(map(str,input().split()))
    x[1],x[2] = (int(x[1]),int(x[2]))
    if x[0] == 'print':
        print(s[x[1]:(x[2]+1)])
    if x[0] == 'reverse':
        s = s[:x[1]] + s[x[1]:(x[2]+1)][::-1] + s[x[2]+1:]
    if x[0] == 'replace':
        s = s[:x[1]] + x[3] + s[x[2]+1:]

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

for x in range(q):
    ip = list(input().split())

    if ip[0] == "print":
        print(st[int(ip[1]):int(ip[2])+1])
    elif ip[0] == "replace":
        ip[1] = int(ip[1])
        ip[2] = int(ip[2])
        temp = st[0:ip[1]] + ip[3] + st[ip[2]+1:]
        st = temp
    elif ip[0] == "reverse":
        ip[1] = int(ip[1])
        ip[2] = int(ip[2])
        temp = st[0:ip[1]] + st[ip[1]:ip[2]+1][::-1] + st[ip[2]+1:]
        st = temp

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

Solution (Python):
def run():
    s=input()
    command_num=int(input())
    
    for i in range(command_num):
        command = input().split()
        command = list(map(lambda x: int(x) if x.isdigit() else x,command))
        
        
        if command[0] == "print":
            a=command[1]
            b=command[2]
            print(s[a:b+1])
            
        elif command[0] == "reverse":
            a=command[1]
            b=command[2]
            
            rev=s[a:b+1]
            rev=rev[::-1]
            
            pre= "" if a==0 else s[0:a]
            post="" if b==len(s)-1 else s[b+1:]
            
            s=pre+rev+post
            
            
        elif command[0] == "replace":
            a=command[1]
            b=command[2]
            p=command[3]
            
            pre= "" if a==0 else s[0:a]
            post="" if b==len(s)-1 else s[b+1:]
            
            s=pre+p+post
            
        else:
            assert False

run()

Solution (Python):
string=list(input())
num=int(input())
orders=[]
for n in range(num):
	orders.append(input().split(' '))

for order in orders:
	if order[0] == 'print':
		a=int(order[1])
		b=int(order[2])
		target_l=string[a:b+1]
		for i in target_l:
			print(i,end="")
		print()
		
	elif order[0] == 'reverse':
		a=int(order[1])
		b=int(order[2])
		target_l=string[a:b+1]
		for i in range(len(target_l)//2):
			tmp=target_l[i]
			target_l[i]=target_l[-(i+1)]
			target_l[-(i+1)]=tmp

		new_l=string[:a]+target_l+string[b+1:]
		string=new_l

	elif order[0] == 'replace':
		a=int(order[1])
		b=int(order[2])
		rep=list(order[3])
		for i,x in enumerate(string[a:b+1]):
			ii=i+a
			string[ii]=rep[i]

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

for idx in range(q):
    e = input().split()
    a = int(e[1])
    b = int(e[2])

    if e[0] == "print":
        print(S[a:b+1])
    elif e[0] == "reverse":
        SS = S[a:b+1]
        S = S[:a] + SS[::-1] + S[b+1:]
    elif e[0] == "replace":
        S = S[:a] + e[3] + S[b+1:]

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

for i in range(q):
    instruction = list(input().split())
    i_name = instruction[0]
    a, b = int(instruction[1]), int(instruction[2])

    if i_name == 'print':
        print(s[a:b+1])
    elif i_name == 'reverse':
        s = s[:a] + ''.join(list(reversed(s[a:b+1]))) + s[b+1:]
    elif i_name == 'replace':
        p = instruction[3]
        s = s[:a] + p + s[b+1:]

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

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 _ in range(q):
    line = input().split()
    if line[0] == 'print':
        print(s[int(line[1]):int(line[2]) + 1])
    elif line[0] == 'reverse':
        s1 = s[:int(line[1])]
        s2 = s[int(line[1]):int(line[2]) + 1]
        s2 = s2[::-1]
        s3 = s[int(line[2]) + 1::]
        s = s1 + s2 + s3
    elif line[0] == 'replace':
        s1 = s[:int(line[1])]
        s2 = s[int(line[2]) + 1:]
        s = s1 + line[3] + s2

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

temp = []
for i in range(q):
    comm = input().split()

    if comm[0] == "replace":
        temp = list(comm[3])
        for i in range(0,int(comm[2])-int(comm[1])+1):
            str[int(comm[1])+i]=temp[i]
        temp.clear()
    elif comm[0] == "reverse":
        for i in reversed(range(int(comm[1]), int(comm[2])+1)):
            temp.append(str[i])
        for i in range(0, int(comm[2])-int(comm[1])+1):
            str[i+int(comm[1])] = temp[i]
        temp.clear()
    else:
        for i in range(int(comm[1]), int(comm[2])+1):
            temp.append(str[i])
        print(''.join(temp))
        temp.clear()

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

ans = S
for _ in range(q):
    A = input().split()
    if A[0]=='print':
        a,b = map(int, A[1:])
        print(ans[a:b+1])
    elif A[0]=='reverse':
        a,b = map(int, A[1:])
        ans = ans[:a] + ans[a:b+1][::-1] + ans[b+1:]
    elif A[0]=='replace':
        a,b = map(int, A[1:3])
        p = A[3]
        ans = ans[:a] + p + ans[b+1:]

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

for i in range(n):
    lst = list(input().split())
    a = int(lst[1])
    b = int(lst[2])

    if lst[0] == 'replace':
        t1 = code[0:a]
        t2 = code[a:b+1]
        t3 = code[b+1:len(code)]
        code = t1 + lst[3] + t3

    elif lst[0] == 'reverse':
        s = code[a:b+1]
        ss = ''.join(list(reversed(s)))
        t1 = code[0:a]
        t2 = code[a:b+1]
        t3 = code[b+1:len(code)]
        code = t1 + ss + t3

    elif lst[0] == 'print':
        print(code[a:b+1])

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

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

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


resolve()

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

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

Solution (Python):
mojiretsu = list(input())
q = int(input())
text = ""

for i in range(q):
    order = list(input().split())
    a = int(order[1])
    b = int(order[2])
    if order[0] == "print":
        for i in range(a, b+1):
            text += mojiretsu[i]
        print(text)
        text = ""

    elif order[0] == "reverse":
        if a == 0:
            mojiretsu = mojiretsu[b::-1] + mojiretsu[b+1:]
        else:
            mojiretsu = mojiretsu[:a] + mojiretsu[b:a-1:-1] + mojiretsu[b+1:]

    elif order[0] == "replace":
        replace_word = list(order[3])
        mojiretsu = mojiretsu[:a] + replace_word + mojiretsu[b+1:]

Solution (Python):
text = list(input())
num = int(input())

for i in range(num):
    orderList = list(input().split(" "))
    start, end = int(orderList[1]), int(orderList[2])
    loopCount = end - start + 1
    
    if orderList[0] == 'replace':
        replaceText = list(orderList[3])
        for i in range(loopCount):
            text[i + start] = replaceText[i]
            
    elif orderList[0] == 'reverse':
        tmpList = []
        for i in range(loopCount):
            tmpList.append(text[i + start])
        for i in range(loopCount):
            text[i + start] = tmpList[loopCount - i - 1]
            
    else:
        answer = []
        for i in range(loopCount):
            answer += text[i + start]
        answer = "".join(answer)
        print(f"{answer}")

Solution (Python):
s = list(input())
q = int(input())
for i in range(q):
    command = input().split()
    a = int(command[1])
    b = int(command[2])
    if command[0] == 'print':
        print(''.join(s[a:b+1]))
    elif command[0] == 'reverse':
        while a < b:
            s[a], s[b] = s[b], s[a]
            a += 1
            b -= 1
    elif command[0] == 'replace':
        p = list(command[3])
        j = 0
        while a + j <= b:
            s[a + j] = p[j]
            j += 1
    else:
        pass

Solution (Python):
s = input()
q = int(input())
for i in range(q):
    tmp = input()
    if tmp[:3] == 'pri':
        o, a, b = tmp.split()
        a = int(a)
        b = int(b)
        print(s[a:b+1])
    elif tmp[:3] == 'rev':
        o, a, b = tmp.split()
        a = int(a)
        b = int(b)
        sl = list(s)
        sl[a:b+1] = reversed(sl[a:b+1])
        s = ''.join(sl)
    else :
        o, a, b, p = tmp.split()
        a = int(a)
        b = int(b)
        sl = list(s)
        sl[a:b+1] = p
        s = ''.join(sl)

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

Solution (Python):
def transform():
    text = input()
    num_order = int(input())

    for _ in range(num_order):
        order = input().split()
        a = int(order[1])
        b = int(order[2])

        if order[0] == "print":
            print(text[a: b + 1])
        elif order[0] == "reverse":
            text = text[0: a] + text[b - len(text): a - len(text) - 1: -1] + text[b + 1:]
        elif order[0] == "replace":
            text = text[0: a] + order[3] + text[b + 1:]


if __name__ == "__main__":
    transform()

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

for i in range(N):
    cmd = list(map(str, input().split()))
    if cmd[0] == 'replace':
        a, b, c = int(cmd[1]), int(cmd[2]), cmd[3]
        if a == 0:
            s = cmd[3] + s[b+1:]
        else:
            s = s[0:a] + cmd[3] + s[b+1:]
    elif cmd[0] == 'reverse':
        a, b = int(cmd[1]), int(cmd[2])
        ss = s[a:b+1]
        ss = list(reversed(ss))
        ss = ''.join(ss)
        if a == 0:
            s = ss + s[b+1:]
        else:
            s = s[0:a] + ss + s[b+1:]
    elif cmd[0] == 'print':
        a, b = int(cmd[1]), int(cmd[2])
        print(s[a:b+1])

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

for i in range(n):
    order = input().split()
    a,b = map(int, order[1:3])
    
    if order[0] == "print":
        print(ori[a:b+1])
    elif order[0] == "reverse":
        tmp=ori[a:b+1]
        ori = ori[:a]+tmp[::-1]+ori[b+1:]
    else:
        ori = ori[:a] + order[3] + ori[b+1:]

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

for i in range(q):
    order = input().split()
    op = order[0]
    a = order[1]
    b = order[2]
    a = int(a)
    b = int(b)

    if op == "replace":
        p = order[3]
        STR = STR[:a] + p + STR[b+1:]
    elif op == "reverse":
        re_STR = STR[a:b+1]
        STR = STR[:a] + re_STR[::-1] + STR[b+1:]
    elif op == "print":
        print(f"{STR[a:b+1]}")

Solution (Python):
string = [x for x in input()]
q = int(input())

for i in range(q):
    order_list = [x for x in input().split()]
    a = int(order_list[1])
    b = int(order_list[2])
    if order_list[0] == "print":
        print("".join(string[a:b+1]))
    elif order_list[0] == "reverse":
        rev = reversed(string[a:b+1])
        rev_s = list(rev)
        string = string[:a] + rev_s + string[b+1:]
    elif order_list[0] == "replace":
        replace_str = [x for x in order_list[3]]
        string = string[:a] + replace_str + string[b+1:]
    else:
        None

Solution (Python):
s = list(input())
q = int(input())
for i in range(q) :
    order = list(input().split())
    if order[0] == "print" :
        for n in range(int(order[1]), int(order[2])+1) :
            print(s[n], sep="", end="")
        print()
        
    elif order[0] == "reverse" :
        new_s = s[int(order[1]) : int(order[2])+1]
        new_s.reverse()
        s[int(order[1]) : int(order[2])+1] = new_s
    
    elif order[0] == "replace" :
        s[int(order[1]) : int(order[2])+1] = list(order[3])

Solution (Python):
t = input()
for _ in[0]*int(input()):
    cmd = input().split()
    if len(cmd) > 3:
        head, a, b, rt = cmd
    else:
        head, a, b = cmd
    a = int(a)
    b = int(b)

    if head == 'print':
        pt = t[a:(b+1)]
        print(pt)
    if head == 'reverse':
        t = t[:a] + ''.join(list(reversed(t[a:(b+1)]))) + t[(b+1):]
    if head == 'replace':
        t = t[:a] + rt + t[(b+1):]

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

Solution (Python):
s = input()
n = int(input())
for _ in range(n):
    ins, *args = input().split()
    if ins == 'print':
        start, end = int(args[0]), int(args[1])+1
        print(s[start:end])
    elif ins == 'reverse':
        start, end = int(args[0]), int(args[1])+1
        s = s[:start] + s[start:end][::-1] + s[end:]
    else:
        start, end, new = int(args[0]), int(args[1])+1, args[2]
        s = s[:start] + args[2] + s[end:]

Solution (Python):
target = input()
num_order = int(input())

for _ in range(num_order):
    order = input().split()
    a = int(order[1])
    b = int(order[2])
    
    if order[0] == "print":
        print(target[a:b + 1])
    elif order[0] == "reverse":
        target = target[:a] + "".join(list(reversed(target[a:b + 1]))) + target[b + 1:]
    else:
        p = order[3]
        target = target[:a] + p + target[b + 1:]

Solution (Python):
tex=input()
n=int(input())
for i in range(n):
    order=list(input().split())
    a=int(order[1])
    b=int(order[2])
    if order[0]=="print":
        print(tex[a:b+1])
    elif order[0]=="reverse":
        if a==0:
            tex=tex[b::-1]+tex[b+1:]
        else:
            tex=tex[:a]+tex[b:a-1:-1]+tex[b+1:]  
    else:
        tex=tex[:a]+order[3]+tex[b+1:]

Solution (Python):
target = input()
m = int(input())
for i in range(m):
    arr= input().split()
    if arr[0] == 'print':
        print(eval('target[' + eval('arr[1]') + ':' + str(int(eval('arr[2]'))+1)+ ']'))
    if arr[0] == 'reverse':
        s_str = eval('target[' + eval('arr[1]') + ':' + str(int(eval('arr[2]'))+1)+ ']')
        target = eval('target[:' +eval('arr[1]') +']') + ''.join(list(reversed(s_str))) + eval('target[' +str(int(eval('arr[2]'))+1) +':]')
    if arr[0] == 'replace':
        target = eval('target[:' +eval('arr[1]') +']') + eval('arr[3]') + eval('target[' + str(int(eval('arr[2]'))+1) +':]')

Solution (Python):
def itp_replace(stri,a,b,c):
    a = int(a)
    b = int(b)
    return stri[:a] + c + stri[b+1:]

def itp_reverse(stri,a,b):
    a = int(a)
    b = int(b)
    return stri[:a] + stri[a:b+1][::-1]+stri[b+1:]

def itp_print(stri,a,b):
    a = int(a)
    b = int(b)
    print(stri[a:b+1])

test_str = input()
test_num = int(input())
order = []
for a in range(test_num):
    temp = input().split()
    order.append(temp)

for a in order:
    if a[0] == 'replace':
        test_str = itp_replace(test_str,a[1],a[2],a[3])
    if a[0] == 'reverse':
        test_str = itp_reverse(test_str,a[1],a[2])
    if a[0] == 'print':
        itp_print(test_str,a[1],a[2])

Solution (Python):
l = input()
n = int(input())
for i in range(n):
    s = input().split()
    if s[0] == 'replace':
        l=l[0:int(s[1])] + s[3] + l[int(s[2])+1:len(l)]
    elif s[0] == 'reverse':
        l = l[0:int(s[1])] + l[int(s[1]):int(s[2])+1][::-1] + l[int(s[2])+1:len(l)]
    else:
        print(f"{l[int(s[1]):int(s[2])+1]}")

Solution (Python):
def main():
  s = list(input())
  num = int(input())
  while num > 0:
    m = list(input().split())
    if m[0] == 'print':
      print(''.join(s[int(m[1]):(int(m[2]) + 1)]))
    elif m[0] == 'reverse':
      temp = s[int(m[1]):(int(m[2]) + 1)]
      temp.reverse()
      for i,v in enumerate(temp):
        s[int(m[1]) + i] = v
    elif m[0] == 'replace':
      temp = list(m[3])
      for i,v in enumerate(temp):
        s[int(m[1]) + i] = v
    num -= 1
main()

Solution (Python):
string = input()
q = int(input())
for _ in range(q):
    operation = tuple(input().split())
    if operation[0] == 'print':
        print(string[int(operation[1]):int(operation[2]) + 1])
    elif operation[0] == 'reverse':
        if int(operation[1]) - 1 < 0:
            string = string =  string[:int(operation[1])] + string[int(operation[2])::-1] + string[int(operation[2]) + 1:]
        else:
            string =  string[:int(operation[1])] + string[int   (operation[2]):int(operation[1]) - 1:-1] + string  [int(operation[2]) + 1:]
    elif operation[0] == 'replace':
        string = string[:int(operation[1])] + operation[3] + string[int(operation[2]) + 1:]

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

for i in range(n):
    order = input().split()
    a, b= map(int, order[1:3])
    if order[0] == "print":
        print(text[a:b+1])
    elif order[0] == "reverse":
        re_text = text[a:b+1]
        text = text[:a] + re_text[::-1] + text[b+1:]
    else :
        text = text[:a] + order[3] + text[b+1:]

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

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

    elif cmd =="reverse":
        s[a:b+1] = reversed(s[a:b+1])
    else:
        s[a:b+1] = c[0]

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

Solution (Python):
istr = input()
iq = int(input())
arr = []
for i in range(0, iq):
	arr.append(list(input().split()))



for i in arr:
	cmd = i[0]
	a, b = int(i[1]), int(i[2])
	if cmd == 'print':  
		print(istr[a:b + 1])
	elif cmd == 'reverse':  
		stemp = ''
		for i in range(b, a - 1, -1):
			stemp = stemp + istr[i]
		istr = istr[:a] + stemp + istr[b + 1:]
	elif cmd == 'replace':  
		p = i[3]
		istr = istr[:a] + p + istr[b + 1:]

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

  for _ in range(q):
    order = list(input().split())
    a,b = int(order[1]), int(order[2])

    if order[0] == 'print':
      print(s[a:b+1])
    elif order[0] == 'reverse':
      s = s[:a] + ''.join(list(reversed(s[a:b+1]))) + s[b+1:]
    else:
      p = order[3]
      s = s[:a] + p + s[b+1:]

if __name__ == '__main__':
  main()