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())
for i in range(q):
    order = input().split()
    a = int(order[1])
    b = int(order[2])
    if order[0] == "print":    
        print(s[a: b+1])
    elif order[0] == "reverse":
        rev_text = s[a: b+1]
        s = s[0: a] + rev_text[::-1] + s[b+1:]
    else:
        p = order[3]
        s = s[0: a] + p + s[b+1:]

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

for i in range(q):
    m = input().split()
    x = int(m[1])
    y = int(m[2])
    if m[0] == "print":
        print(s[x:y+1])
    elif m[0] == "reverse":
        s = s[0:x] + "".join(list(reversed(s[x:y+1]))) + s[y+1:]
    else:
        s = s[0:x] + m[3] + s[y+1:]

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

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

for i in range(N):
    run_list = list(input().split())
    if run_list[0] == "print":
        a = int(run_list[1])
        b = int(run_list[2])
        print(S[a:b+1])
    elif run_list[0] == "reverse":
        a = int(run_list[1])
        b = int(run_list[2])
        S = S[:a] + S[a:b+1][::-1] + S[b+1:]

    else:
        a = int(run_list[1])
        b = int(run_list[2])
        p = run_list[3]
        S = S[:a] + p + S[b+1:]

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

for t in range(n):
    order = list(input().split())

    if "replace" == order[0]:
        left = int(order[1])
        right = int(order[2])
        text = text[:left] + order[3] + text[right + 1:]
    elif "reverse" == order[0]:
        left = int(order[1])
        right = int(order[2])
        text = text[:left] + text[left:right + 1][::-1] + text[right + 1:]
    elif "print" == order[0]:
        print(text[int(order[1]): int(order[2]) + 1])

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

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

Solution (Python):
def print_list(s, a, b):
    print(s[a:b+1])

def reverse_list(s, a, b):
    s1 = "".join(s[:a])
    s2 = "".join(reversed(s[a:b+1]))
    s3 = "".join(s[b+1:])
    return list(s1+s2+s3)

def replace_list(s, a, b, p):
    s1 = "".join(s[:a])
    s3 = "".join(s[b+1:])
    return list(s1+p+s3)

s = list(input())
pl = []
cmd = []
n = int(input())
i = 0

while n > i:
    cmd = input().split()
    if cmd[0] == "print":
        pl.append("".join(s[int(cmd[1]):int(cmd[2])+1]))
    elif cmd[0] == "reverse":
        s = reverse_list(s, int(cmd[1]), int(cmd[2]))
    elif cmd[0] == "replace":
        s = replace_list(s, int(cmd[1]), int(cmd[2]), cmd[3])
    i += 1

for p in pl:
    print(p)

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

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

Solution (Python):

string = list(input())
q = int(input())

def print_func(head, end):
    string_p = ''
    for i in range(head,end + 1):
        string_p += string[i]
    print(string_p)

def reverse_func(head, end):
    i = 0
    while head + i <= end - i:
        string[head + i],string[end - i] = string[end - i],string[head + i]
        i += 1

def replace_func(head, end, r_str):
    l_r_str = list(r_str)
    for i in range(end - head + 1):
        string[head + i] = l_r_str[i]

for i in range(q):
    l = list(input().split())
    l[1] = int(l[1]); l[2] = int(l[2])
    if l[0] == 'print':
        print_func(l[1],l[2])
    elif l[0] == 'reverse':
        reverse_func(l[1],l[2])
    else:
        replace_func(l[1],l[2],l[3])

Solution (Python):
m = input()
n = int(input())
for i in range(n):
    ord = input().split()
    a,b =map(int,ord[1:3])
    if ord[0]=='print':
        print(m[a:b+1])
    elif ord[0]=='reverse':
        rev = m[a:b+1]
        m = m[:a]+rev[::-1]+m[b+1:]
    else:
        rep = ord[3]
        m=m[:a]+rep+m[b+1:]

Solution (Python):
strings = input()

q = int(input())

for i in range(q):
    order = list(input().split())
    a, b = map(int, order[1:3])
    if order[0] == 'print':
        print(strings[a:b+1])
    elif order[0] == 'reverse':
        re_strings = strings[a:b+1]
        strings = strings[:a] + re_strings[::-1] + strings[b+1:]
    else:
        strings = strings[:a] + order[3] + strings[b+1:]

Solution (Python):
def resolve():
    S = input()
    N = int(input())
    L = [list(map(str, input().split())) for _ in range(N)]
    
    for i in range(N):
        start = int(L[i][1])
        end = int(L[i][2]) + 1
        if L[i][0] == 'print':
            print(S[start:end])
        elif L[i][0] == 'reverse':
            S = S[:start] + S[start:end][::-1] + S[end:]
        else:
            S = S[:start] + L[i][3] + S[end:]

if __name__ == "__main__":
    resolve()

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

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

for _ in range(q):
    l = input().split()
    cmd = l[0]
    a = int(l[1])
    b = int(l[2])
    if cmd == 'print':
        print(''.join(str[a:b+1]))
    elif cmd == 'reverse':
        str[a:b+1] = reversed(str[a:b+1])
    else:
        str[a:b+1] = l[3]

Solution (Python):
def defPrint(s,e):
  global str
  print(str[s:e+1])

def defReverse(s,e):
  global str
  strList = list(str)
  rStrList = strList[s:e+1][::-1]
  for i,x in enumerate(rStrList) :
    strList[s + i] = x
  str = "".join(strList)  
  
def defReplace(s,e,r):
  global str
  if s == 0:
    str = r + str[e+1:]
  else:
    str = str[0:s] + r + str[e+1:]

str = input()
q = int(input())

for i in range(q):
  cmd = list(input().split(" "))
  if cmd[0] == 'print' :
    defPrint(int(cmd[1]),int(cmd[2]))
  if cmd[0] == 'reverse' :
    defReverse(int(cmd[1]),int(cmd[2]))
  if cmd[0] == 'replace' :
    defReplace(int(cmd[1]),int(cmd[2]),cmd[3])

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

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

for _ in range(n):
    command = input().split() 
    if command[0] == "replace" :
        text = text[:int(command[1])] + command[3] + text[int(command[2])+1:]
        
    elif command[0] == "print" :
        print(text[int(command[1]):int(command[2])+1])
        
    elif command[0] == "reverse" :
        rev_text = text[int(command[1]):int(command[2])+1]
        text = text.replace(text[int(command[1]):int(command[2])+1],rev_text[::-1])

Solution (Python):
base_str = input()
order_num = int(input())
for i in range(order_num):
    order_str = input().split()

    order_s = int(order_str[1])
    order_e = int(order_str[2])
    if order_str[0] == 'print':
        print('{}'.format(base_str[order_s : order_e + 1]))
    elif order_str[0] == 'reverse':
        if len(base_str) == order_e:
            tmp = base_str[order_s:]
        else:
            tmp = base_str[order_s:order_e + 1]
        tmp_r = tmp[::-1]
        if order_s -1 < 0:
            tmp_new = tmp_r + base_str[order_e + 1:]
        else:
            tmp_new = base_str[:order_s] + tmp_r + base_str[order_e + 1:]
        base_str = tmp_new
    elif order_str[0] == 'replace':
        tmp = base_str[:order_s] + order_str[3] + base_str[order_e + 1:]
        base_str = tmp

Solution (Python):
l_str = input()
q = int(input())
ord = []
for i in range(q):
    ord = list(input().split())
    if ord[0] == "print":
        a = int(ord[1])
        b = int(ord[2])
        print(l_str[a:b+1])
    if ord[0] == "reverse":
        a = int(ord[1])
        b = int(ord[2])
        c = l_str[a:b+1][::-1]
        l_str = l_str[:a] + c + l_str[b+1:]
    if ord[0] == "replace":
        a = int(ord[1])
        b = int(ord[2])
        p = ord[3]
        l_str = l_str[:a] + p + l_str[b+1:]

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

Solution (Python):
STR = input()
Q = int(input())
for _ in range(Q):
    com = input().split()
    if com[0] == 'print':
        a, b = int(com[1]), int(com[2])
        print(STR[a:b + 1])
    if com[0] == 'reverse':
        a, b = int(com[1]), int(com[2])
        STR = STR[:a] + STR[a:b + 1][::-1] + STR[b + 1:]
    if com[0] == 'replace':
        a, b, alt = int(com[1]), int(com[2]), com[3]
        STR = STR[:a] + alt + STR[b + 1:]

Solution (Python):
def main():
    str = input()
    q = int(input())
    for _ in range(0, q):
        queries = input().split()
        command = queries[0]
        if command == 'print':
            a = int(queries[1])
            b = int(queries[2])
            print(str[a:b + 1])
        elif command == 'reverse':
            a = int(queries[1])
            b = int(queries[2])
            str = str[:a] + ''.join(list(reversed(str[a:b + 1]))) + str[b + 1:]
        elif command == 'replace':
            a = int(queries[1])
            b = int(queries[2])
            p = queries[3]
            str = str[:a] + p + str[b + 1:]

if __name__ == '__main__':
    main()

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

def p (a:int,b:int):
    print (s[a:b+1])

def rev (a:int,b:int):
    tmp = s[a:b+1]
    return s[:a]+tmp[::-1]+s[b+1:]

def rep (a:int,b:int,p:str):
    return s[:a]+p+s[b+1:]

for _ in range(n):
    i = input().split()
    if i[0] == "print":
        p (int(i[1]),int(i[2]))
    elif i[0] == "reverse":
        s = rev (int(i[1]),int(i[2]))
    else:
        s = rep (int(i[1]),int(i[2]),i[3])

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

Solution (Python):
str = input()
question = int(input())
for q in range(question):
    line = input()
    if line.find("print") != -1:
        order, a, b = (x for x in line.split())
        print(str[int(a):int(b)+1])
    elif line.find("reverse") != -1:
        order, a, b = (x for x in line.split())
        if(a == 0): str = str[int(a):int(b)+1][::-1] + str[int(b)+1:len(str)]
        else: str = str[:int(a)] + str[int(a):int(b)+1][::-1] + str[int(b)+1:len(str)]
    elif line.find("replace") != -1:
        order, a, b, word = (x for x in line.split())
        str = str[:int(a)] + word + str[int(b)+1:len(str)]

Solution (Python):
def print_command(string, a, b):
    a, b = int(a), int(b)

    print(string[a:b + 1])

    return string


def reverse_command(string, a, b):
    a, b = int(a), int(b)

    return string[:a] + (string[a:b + 1])[::-1] + string[b + 1:]


def replace_command(string, a, b, replace):
    a, b = int(a), int(b)

    return string[:a] + replace + string[b + 1:]


if __name__ == "__main__":
    string = input()

    num_commands = int(input())

    commands = []

    for _ in range(num_commands):
        commands.append(input().split())

    command_function_table = {
        "print": print_command,
        "reverse": reverse_command,
        "replace": replace_command
    }

    for command in commands:
        string = command_function_table[command[0]](string, *(command[1:]))

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

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

for i in range(N):
    list1 = input().split()
    if list1[0] == "print":
        print("".join(S[int(list1[1]):int(list1[2])+1]))
    elif list1[0] == 'reverse':
        S[int(list1[1]):int(list1[2])+1] = reversed(S[int(list1[1]):int(list1[2])+1])
    else:
        S[int(list1[1]):int(list1[2])+1] = list1[3]

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

while N > 0:
    command = input().split()

    if command[0] == "print":
        a = int(command[1])
        b = int(command[2])

        print(S[a:b+1])
    elif command[0] == "reverse":
        a = int(command[1])
        b = int(command[2])

        S = S[:a]+S[a:b+1][::-1]+S[b+1:]
    

    else:
        a = int(command[1])
        b = int(command[2])
        p = command[3]

        S = S[:a] + p + S[b+1:]


    N -= 1

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

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

Solution (Python):
str = input()
q = int(input())
for i in range(q):
    order = input().split()
    a,b = map(int,order[1:3])
    if order[0] == 'print':
        print(str[a:b+1])
    elif order[0] == 'reverse':
        rev = str[a:b+1]
        str = str[:a]+rev[::-1]+str[b+1:]
    else:
        l = len(str)
        str = str[:a]+order[3]+str[b+1:]

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

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

    if command[0] == 'replace':
        a = int(command[1])
        b = int(command[2]) + 1
        s = s[:a] + command[3] + s[b:]
    elif command[0] == 'reverse':
        a = int(command[1])
        b = int(command[2]) + 1
        s = s[:a] + s[a:b][::-1] + s[b:]
    else:
        a = int(command[1])
        b = int(command[2]) + 1
        print(s[a:b])

Solution (Python):
s = input()
for i in [0]*int(input()):
    l = input().split()
    if l[0] == "print":print(s[int(l[1]):int(l[2])+1])
    elif l[0] == "replace":s = s[0:int(l[1])] + l[3] + s[int(l[2])+1:]
    else:s = s[:int(l[1])] + "".join(reversed(s[int(l[1]):int(l[2])+1])) +s[int(l[2])+1:]

Solution (Python):
s = input()
q = int(input())
for i in range(q):
    line = input()
    if 'print' in line:
        op, a, b = line.split()
        a = int(a)
        b = int(b)
        print(s[a:b+1])
    elif 'reverse' in line:
        op, a, b = line.split()
        a = int(a)
        b = int(b)
        reversed_substring = ''.join(list(reversed(s[a:b+1])))
        s = s[:a] + reversed_substring + s[b+1:]
    elif 'replace' in line:
        op, a, b, p = line.split()
        a = int(a)
        b = int(b)
        s = s[:a] + p + s[b+1:]

Solution (Python):
string = str(input())
n = int(input())
conversion = [input().split() for i in range(n)]

for conv in conversion:
    func = conv[0]
    if func == "replace":
        a, b, p = int(conv[1]), int(conv[2])+1, conv[3]
        string = string[:a] + p + string[b:]
    else:
        a, b = int(conv[1]), int(conv[2]) + 1
        if func == "print":
            print(string[a:b])
        else:
            string = string.replace(string[a:b], string[a:b][::-1])

Solution (Python):
str=input()
str=list(str)
N=int(input())
for i in range(N):
    A=list(input().split())
    A[1],A[2]=[int(A[1]),int(A[2])]
    
    if A[0]=="print":
        tmp=[]
        for j in range(A[1],A[2]+1):
            tmp+=str[j]
        print("".join(tmp))
        
    elif A[0]=="reverse":
        tmp=[]
        for j in range(0,A[2]-A[1]+1):
            tmp+=str[A[2]-j]
        for j in range(0,A[2]-A[1]+1):
            str[A[1]+j]=tmp[j]
    elif A[0]=="replace":
        rep=list(A[3])
        for j in range(0,A[2]-A[1]+1):
            str[A[1]+j]=rep[j]

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

for _ in range(n):
    command = input().split()
    st = int(command[1])
    en = int(command[2])

    if command[0] == "print":
        print(text[st:en+1])

    elif command[0] == "reverse":
        if st == 0:
            text = text[en::-1] + text[en+1:]
        else:
            text = text[:st] + text[en:st-1:-1] + text[en+1:]

    elif command[0] == "replace":
        text = text[:st] + command[3] + text[en+1:]

Solution (Python):
s=' '+input()+' '
for _ in range(int(input())):
    l=input().split()
    o=l[0]
    a=int(l[1])+1; b=int(l[2])+2
    if o=='print': print(s[a:b])
    if o=='reverse': s=s[:a]+s[b-1:a-1:-1]+s[b:]
    if o=='replace': s=s[:a]+l[3]+s[b:]

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())):
    a, *b = input().split()
    if a == "replace":
        *b, p = b
    i, j = map(int, b)
    
    if a == "print":
        print(s[i:j+1])
    elif a == "reverse":
        s = s[:i] + s[i:j+1][::-1] + s[j+1:]
    else:
        s = s[:i] + p + s[j+1:]

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

Solution (Python):
def print_str(a, b, str) -> None:
    for i in range(a, b + 1):
        print(str[i], end="")
    print()


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

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

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

    if order_set[0] == "replace":
      string = string[:a] + order_set[3] + string[b+1:]
      
    if order_set[0] == "reverse":
      string = string[:a] + string[a:b+1][::-1] + string[b+1:]
      
    if order_set[0] == "print":
      print(string[a:b+1])

Solution (Python):



in_str = list(input())
n = int(input())


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

    if p[0]=='replace':
        a = int(p[1])
        b = int(p[2])
        q = p[3]
        for j in range(len(q)):
            in_str[j+a] = q[j]
    elif p[0]=='reverse':
        a = int(p[1])
        b = int(p[2])
        tmp = in_str[a:b+1]
        tmp = tmp[::-1]
        for j in range(len(tmp)):
            in_str[j+a] = tmp[j]
    elif p[0]=='print':
        a = int(p[1])
        b = int(p[2])
        ans = in_str[a:b+1]
        print("".join(ans))

Solution (Python):
str=input()
q=int(input())
i=0
while i<q:
    ord=list(input().split())
    if ord[0]=="print":
        print(str[int(ord[1]):int(ord[2])+1])
    if ord[0]=="reverse":
        str_i = str[:int(ord[1])]
        str_re = str[int(ord[1]):int(ord[2])+1]
        str_re = str_re[::-1]
        str_f = str[int(ord[2])+1:]
        str=str_i+str_re+str_f
    if ord[0]=="replace":
        str_i = str[:int(ord[1])]
        str_f = str[int(ord[2])+1:]
        str=str_i+ord[3]+str_f
    i+=1

Solution (Python):
s = input()
for i in [0]*int(input()):
    command = input().split()
    a, b = int(command[1]), int(command[2])
    b += 1
    if command[0] == 'replace':
        s = s[:a] + command[3] + s[b:]
    elif command[0] == 'reverse':
        s = s[:a] + s[a:b][::-1] + s[b:]
    else:
        print(s[a:b])

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

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

for cmd, left, right, *etc in order:
    left=int(left)
    right=int(right) + 1
    if cmd=='replace':
        s = s[:left] + etc[0] + s[right:]
    elif cmd=='reverse':
        s = s[:left] + s[left:right][::-1] + s[right:]
    else:
        print(s[left:right])

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

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

Solution (Python):
s = list(input())
q = int(input())
for _ in range(q):
    line = input().split()
    if line[0][2] == "p":
        s = s[:int(line[1])] + list(line[3]) + s[int(line[2])+1:]
    elif line[0][2] == "v":
        s = s[:int(line[1])] + s[int(line[1]):int(line[2])+1][::-1] + s[int(line[2])+1:]
    elif line[0][0] == "p":
        print("".join(s[int(line[1]):int(line[2])+1]))

Solution (Python):
s=input()
n=int(input())
for i in range(n):
    l=list(input().split())
    if l[0]=="print":
        print(s[int(l[1]):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]=="replace":
        s=s[:int(l[1])]+l[3]+s[int(l[2])+1:]

Solution (Python):
def PRINT(S,a,b):
    print(S[a:b+1])
def REPLACE(S,T,a,b):
    return S[:a] + T + S[b+1:]
def REVERSE(S,a,b):
    tmp = S[a:b+1]
    return S[:a] + tmp[::-1] + S[b+1:] 

S = input()
q = int(input())

for i in range(q):
    order = list(input().split())
    a = int(order[1])
    b = int(order[2])
    if order[0] == "replace":
        S = REPLACE(S,order[3],a,b)
    elif order[0] == "reverse":
        S = REVERSE(S,a,b)
    else:
        PRINT(S,a,b)

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

for i in range(q):
    x = input().split()
    
    if len(x) == 3:
        order = x[0]
        first = int(x[1])
        second = int(x[2])
        
    else:
        order = x[0]
        first = int(x[1])
        second = int(x[2])
        change = x[3]
        
    
    if order == "print":
        print("".join(sentence[first : (second + 1)]))
        
    elif order == "reverse":
        if len(sentence[first : second + 1]) % 2 == 0:
            for i in range(int(len(sentence[first : second + 1]) / 2)):
                tmp = sentence[first + i]
                sentence[first + i] = sentence[second - i] 
                sentence[second - i] = tmp
                
        else:
            for i in range(len(sentence[first : second + 1] )// 2):
                tmp = sentence[first + i]
                sentence[first + i] = sentence[second - i] 
                sentence[second - i] = tmp
            
    else:
        sentence[first : second + 1] = change

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

Solution (Python):
moji = str(input())
num = int(input())
for i in range(num):
  s = input().rstrip().split(' ')
  command = str(s[0])
  if command == "print":
    start = int(s[1])
    end = int(s[2])
    print(moji[start:end+1])
  elif command == "reverse":
    start = int(s[1])
    end = int(s[2]) + 1
    moji2 = moji[start:end]
    moji3 = ''.join(list(reversed(moji2)))
    moji = moji[:start] + moji3 + moji[end:]
  elif command == "replace":
    start = int(s[1])
    end = int(s[2]) + 1
    beforerep = moji[start:end+1]
    rep = str(s[3])
    moji = moji[:start] + rep + moji[end:]

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

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

Solution (Python):
s=list(input())
for i in range(int(input())):
    q=input().split()
    a,b=int(q[1]),int(q[2])
    
    if q[0]=="replace":
        s[a:b+1]=q[3]

    elif q[0]=="reverse":
        s[a:b+1]=reversed(s[a:b+1])
        
    else:print(*s[a:b+1],sep="")

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

for i in range(q):
    input_value = list(input().split())
    if len(input_value) == 4:
        c, a, b, p = ' '.join(input_value).split()
    else:
        c, a, b = ' '.join(input_value).split()

    a = int(a)
    b = int(b)
    
    if c == 'replace':
        s = s[:a] + p + s[b+1:]
    
    elif c == 'reverse':
        s = s[:a] + ''.join(list(reversed(s[a:b+1]))) + s[b+1:]

    
    elif c == 'print':
        print(s[a:b+1])

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

for i in range(q):
    cmdln = [i for i in input().split()]
    cmd = cmdln[0]
    a, b = (int(i) for i in cmdln[1:3])
    if cmd == "print":
        print(string[a:b+1])
    elif cmd == "reverse":
        string = string[:a] + string[a:b+1][::-1] + string[b+1:]
    elif cmd == "replace":
        p = cmdln[3]
        string = string[:a] + p + string[b+1:]

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

for i in range(q):
    s = input().split()
    if s[0] == "print":
        ans = char[int(s[1]):int(s[2])+1]
        print("".join(ans))
    elif s[0] == "reverse":
        tmp = char[int(s[1]):int(s[2])+1]
        result = ""
        for j in range(len(tmp)):
            result += tmp[-1-j]
        for i in range(len(result)):
            char[int(s[1])+i] = result[i]
    else:
        char = char[:int(s[1])] + list(s[3]) + char[int(s[2])+1:]

Solution (Python):
import math
import copy
from copy import deepcopy
import sys
import fractions

from functools import reduce

import decimal
import heapq
import collections
import itertools
from operator import mul

sys.setrecursionlimit(100001)







def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList



def getInputListStr():
    outputData = []
    inputData = input().split()
    outputData = [str(n) for n in inputData]

    return outputData

def replace(s, a, b, new_s):
    s = s[:a] + new_s + s[b+1:]
    return s

def reverse(s, a, b):
    tmp = s[a:b+1]
    tmp2 = tmp[::-1]
    s = s[:a] + tmp2 + s[b+1:]
    return s

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()
n = int(input())
for _ in range(n):
    op = list(input().split())
    if op[0]=='replace':
        s = s[:int(op[1])]+op[3]+s[int(op[2])+1:]
    elif op[0]=='reverse':
        s = s[:int(op[1])]+''.join(list(reversed(s[int(op[1]):int(op[2])+1])))+s[int(op[2])+1:]
    else : print(s[int(op[1]):int(op[2])+1])

Solution (Python):
st=input()
loop=int(input())
for _ in range(loop):
    order =input().split()
    if order[0] == "print":
        print(st[
            int(order[1]) :
            int(order[2])+1
            ])
    elif order[0] == "reverse":
        gyaku="".join(list(reversed(st[int(order[1]) : int(order[2])+1])))
        st=st[:int(order[1])]+gyaku+st[int(order[2])+1:]
    elif order[0] == "replace":
        st=st[:int(order[1])]+order[3]+st[int(order[2])+1:]

Solution (Python):
import re
S = input()
q = int(input())
C = []
for i in range(q):
    C.append(re.split('\s',input()))
for i in C:
    if i[0] == 'replace':
        a = int(i[1])
        b = int(i[2])
        S = S[0:a] + i[3][0:b-a+1] + S[b+1:len(S)]
    elif i[0] == 'reverse':
        a = int(i[1])
        b = int(i[2])
        S = S[0:a] + S[a:b+1][::-1] + S[b+1:len(S)]
    else:
        a = int(i[1])
        b = int(i[2])
        print(S[a:b+1])