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):
word = str(input())
wlist = []
for i in word:
    wlist.append(i)
n = int(input())
for i in range(n):
    com = list(input().split())
    a = int(com[1])
    b = int(com[2])
    if (com[0] == 'print'):
        for k in range(a, b + 1):
            print(wlist[k], end ='')
        print()
    elif (com[0] == 'reverse'):
        decoy = []
        for k in range(a, b+1):
            decoy.append(wlist[b+a-k])
        for l in range(b-a+1):
            wlist[a+l] = decoy[l]
    elif (com[0] == 'replace'):
        p = str(com[3])
        plist = []
        for k in p:
            plist.append(k)
        for l in range(b-a+1):
            wlist[a+l] = plist[l]

Solution (Python):
word = str(input())
wlist = []
for i in word:
    wlist.append(i)
n = int(input())
for i in range(n):
    com = list(input().split())
    a = int(com[1])
    b = int(com[2])
    if (com[0] == 'print'):
        for k in range(a, b + 1):
            print(wlist[k], end ='')
        print()
    elif (com[0] == 'reverse'):
        decoy = []
        for k in range(a, b+1):
            decoy.append(wlist[b+a-k])
        for l in range(b-a+1):
            wlist[a+l] = decoy[l]
    elif (com[0] == 'replace'):
        p = str(com[3])
        plist = []
        for k in p:
            plist.append(k)
        for l in range(b-a+1):
            wlist[a+l] = plist[l]

Solution (Python):
s = input()
for _ in range(int(input())):
	o = list(map(str, input().split()))
	a = int(o[1])
	b = int(o[2])
	if o[0] == "print":
		print(s[a:b+1])
	elif o[0] == "reverse":
		s = s[:a] + s[a:b+1][::-1] + s[b+1:]
	else:
		s = s[:a] + o[3] + 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()
n=int(input())
for _ in range(n):
    tmp=list(map(str,input().split()))
    a,b=int(tmp[1]),int(tmp[2])+1
    if tmp[0]=="print":
        print(s[a:b])
    elif tmp[0]=="reverse":
        stmp=s[a:b]
        s=s[:a]+stmp[::-1]+s[b:]
    else:
        p=tmp[3]
        s=s[:a]+p+s[b:]

Solution (Python):
string=input()
q=int(input())
for i in range(q):
    lst=input().split()
    order=lst[0]
    if order=='reverse':
        a=int(lst[1])
        b=int(lst[2])
        extraction=''
        for l in range(a,b+1):
            letter=string[l]
            extraction+=letter
        oppose=extraction[::-1]
        lst=list(string)
        lst[a:b+1]=oppose
        string="".join(lst)
    if order=='replace':
        a=int(lst[1])
        b=int(lst[2])
        p=lst[3]
        move=p
        lst=list(string)
        lst[a:b+1]=move
        string="".join(lst)
    if order=='print':
        a=int(lst[1])
        b=int(lst[2])
        extraction=''
        for o in range(a,b+1):
            letter=string[o]
            extraction+=letter
        print(extraction)

Solution (Python):
st = str(input())
q = int(input())
com = []
for i in range(q):
	com.append(input().split())
for k in com:
	if k[0] == "print":
		print(st[int(k[1]):int(k[2])+1])
	elif k[0] == "reverse":
		s = list(st[int(k[1]):int(k[2])+1])
		s.reverse()
		ss = "".join(s)
		st = st[:int(k[1])] + ss + st[int(k[2])+1:]
	else:
		st = st[:int(k[1])] + k[3] + st[int(k[2])+1:]

Solution (Python):
t = input()
n = int(input())
for i in range(n):
    orders = input().split()
    order = orders[0]
    a = int(orders[1])
    b = int(orders[2])

    if order == "replace":
        word = orders[3]
        t = t[:a] + word + t[b+1:]
    if order == "print":
        print(t[a:b+1])
    if order == "reverse":
        t = t[:a] + t[a:b+1][::-1]+ t[b+1:]

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





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

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

Solution (Python):
s = input()
q = int(input())
for _ in range(q):
    query = list(input().split())
    l,r = map(int,query[1:3])
    if query[0] == 'replace':
      p = query[3]
      s = s[:l] + p + s[r+1:]
    elif query[0] == 'reverse':
      s = s[:l] + ''.join(list(reversed(s[l:r+1]))) + s[r+1:]
    else:
      print(s[l:r+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):


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):
Str = input()
q = int(input())
for i in range(q):
    order = list(input().split())
    o = order[0]
    a = int(order[1])
    b = int(order[2])
    
    if o=='print':
        print(Str[a:b+1])
    
    if o=='reverse':
        StrL = list(Str)
        t = list(Str[a:b+1])
        j = len(t)-1
        for i in range(a,b+1):
            StrL[i] = t[j]
            j -= 1
        Str = ''.join(StrL)
    
    if o=='replace':
        p = list(order[3])
        StrL = list(Str)
        j = 0
        for i in range(a,b+1):
            StrL[i] = p[j]
            j += 1
        Str = ''.join(StrL)

Solution (Python):
def ss_reverse(ss,a,b):
    rev = ss[a:b+1]
    rev = rev[::-1]
    edited = ss[:a] + rev + ss[b+1:]
    return edited

def ss_replace(ss,a,b,word):
    edited = ss
    edited= ss[:a] + word + ss[b+1:]
    return edited

def print_result(ss,a,b):
    print(ss[a:b+1])

ss = input()
n = int(input())

for i in range(n):
    I = input().split()
    if len(I) == 4:
        ss = ss_replace(ss,int(I[1]),int(I[2]),I[3])
    
    if I[0] == "reverse" :
        ss = ss_reverse(ss,int(I[1]),int(I[2]))

    if I[0] == "print" :
        print_result(ss,int(I[1]),int(I[2]))

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

Solution (Python):




def main():
    s = input()
    q = int(input())
    for i in range(q):
        l = list(input().split())
        a = int(l[1])
        b = int(l[2])
        if l[0] == "print":
            print(s[a:b+1])
        elif l[0] == "reverse":
            s = s[0:a] + s[a:b+1:][::-1] + s[b+1:]
        elif l[0] == "replace":
            s = s[0:a] + l[3] + s[b+1:]
        else:
            pass


if __name__ == '__main__':
    main()

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

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

  if "replace" in c:
    s = s[:a] + c[3] + s[b+1:]
        
  if "reverse" in c:
    u = s[a:b+1]
    s = s[:a] + u[:: -1] +s[b + 1:]

  if "print" in c:
    print(s[a:b+1], sep = '')

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

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

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

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

Solution (Python):
class String:
    def __init__(self,letter):
        self.letter=letter
        self.memory=''
    def println(self,start,end):
        print(self.letter[start:(end+1)])
    def replace(self,start,end,alt):
        self.memory=''

        if(start!=0 and end!=(len(self.letter)-1)):
            self.memory=self.letter[0:start]+alt+self.letter[(end+1):]
        elif(start==0):
            self.memory=alt+self.letter[(end+1):]
        elif(end==(len(self.letter)-1)):
            self.memory=self.letter[:start]+alt
        self.letter=self.memory

    def reverse(self,start,end):
        self.memory=''
        if(start==0):
            obj=self.letter[end::-1]
            self.memory=obj+self.letter[(end+1):]
        else:
            obj=self.letter[end:(start-1):-1]
            self.memory=self.letter[0:start]+obj+self.letter[(end+1):]
        self.letter=self.memory
    def check(self):
        return self.letter
    

val=input()
q=int(input())
my_str=String(val)
for i in range(q):
    command=input().split()
    if(command[0]=="print"):
        my_str.println(int(command[1]),int(command[2]))
    elif(command[0]=="replace"):
        my_str.replace(int(command[1]),int(command[2]),command[3])
    elif(command[0]=="reverse"):
        my_str.reverse(int(command[1]),int(command[2]))

Solution (Python):
str = input()
lstr = list(str)

num = int(input())

for i in range(num):
    order = input().split()

    if (order[0] == "print"):
        onum = list(map(int,order[1:3]))

        for i in range(onum[0],onum[1]+1):
            print(lstr[i],end = "")
        print("")

    elif (order[0] == "reverse"):
        onum = list(map(int,order[1:3]))
        if (onum[0] == 0):
            tmp1 = lstr[0:onum[1]+1]
            tmp1.reverse()
            tmp2 = lstr[onum[1]+1:]
            lstr = tmp1 + tmp2

        else:
            tmp1 = lstr[:onum[0]]
            tmp2 = lstr[onum[0]:onum[1]+1]
            tmp2.reverse()
            tmp3 = lstr[onum[1]+1:]
            lstr = tmp1 + tmp2 +tmp3

    elif (order[0] == "replace"):
        onum = list(map(int,order[1:3]))
        restr = list(order[3])

        for i in range(onum[0],onum[1]+1):
            lstr[i] = restr[i-onum[0]]

Solution (Python):
def mapt(fn, *args):
    return list(map(fn, *args))

def Array(listseq):
    return mapt(Vector, listseq)

def Vector(line):
    return mapt(Atom, line.split(" "))

def Atom(segment):
    try:
        return int(segment)
    except ValueError:
        try:
            float(segment)
        except ValueError:
            return segment


def parse_second(rest):
    first, end, strings = rest[0], rest[1], rest[-1]
    return first, end+1, strings


def main(word, orders):
    parsed =Array(orders)
    word = list(word)
    for cmd, *rest in parsed:
        first, end, strings = parse_second(rest)

        if    cmd == "replace": word[first:end] = strings
        elif  cmd == "reverse": word[first:end] = reversed(word[first:end])
        else: print("".join(word[first:end]))



word = input()
times = int(input())
orders = [input() for _ in range(times)]
main(word, orders)

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):
N=input()
Z=int(input())
for i in range(Z):
    C=list(input().split())
    at=int(C[1])
    bt=int(C[2])
    if C[0]=="print":
      print(N[at:bt+1])
    elif C[0]=="replace":
      N=N[:at]+C[3]+N[bt+1:]
    else:
      re=N[at:bt+1]
      N=N[:at]+re[::-1]+N[bt+1:]

Solution (Python):
s = input()
n = int(input())
for i in range(n):
    q = input().split()
    q1 = int(q[1])
    q2 = int(q[2]) + 1
    if q[0] == "print":
        sl = list(s)
        print("".join(sl[q1:q2]))
    elif q[0] == "reverse":
        sl = list(s)
        bb = sl[q1:q2]
        bb.reverse()
        s = "".join(sl[:q1] + bb + sl[q2:])
    elif q[0] == "replace":
        sl = list(s)
        s = "".join(sl[:q1]) + q[3] + "".join(sl[q2:])

Solution (Python):
str0=input()
q=int(input())
for i in range(q):
  ord=input()
  if "print" in ord:
    buff=ord.split()
    a=int(buff[1])
    b=int(buff[2])
    print(str0[a:b+1])
  if "replace" in ord:
    buff=ord.split()
    a=int(buff[1])
    b=int(buff[2])
    str0=str0[0:a]+buff[3]+str0[b+1:]
  if "reverse" in ord:
    buff=ord.split()
    a=int(buff[1])
    b=int(buff[2])
    tmp=str0[a:b+1]
    str0=str0[0:a]+''.join(list(reversed(tmp)))+str0[b+1:]

Solution (Python):
characters = list(input())
n = int(input())
for i in range(n):
  order_list = list(map(str, input().split()))
  order_list[1] = int(order_list[1])
  order_list[2] = int(order_list[2])
  if order_list[0] == 'replace':
    for j in range(order_list[1], order_list[2]+1):
      characters[j] = order_list[3][j-order_list[1]]
  if order_list[0] == 'reverse':
    sliced_part = characters[order_list[1]:order_list[2]+1]
    sliced_part = sliced_part[::-1]
    for j in range(order_list[1], order_list[2]+1):
      characters[j] = sliced_part[j-order_list[1]]
  if order_list[0] == 'print':
    for i in range(order_list[1], order_list[2]+1):
      print(characters[i], end='')
    print('')

Solution (Python):
def print_ab(sent, a, b):
    res = sent[a:b + 1]
    return res

def reverse_ab(sent, a, b):
    top = sent[:a]
    las = sent[b+1:]
    tag = sent[a:b+1]
    n = len(tag)
    rev = ""
    for i in range(n):
        rev = rev + tag[n - i - 1]
    rev = top + rev + las
    return rev

def replace_abp(sent, a, b, p):
    top = sent[:a]
    las = sent[b+1:]
    rep = top + p + las
    return rep





sent = input()
op = int(input())
results = []
for i in range(op):
    oder = list(map(str, input().split()))
    if oder[0] == "print":
        res = print_ab(sent, int(oder[1]), int(oder[2]))
        results.append(res)
    elif oder[0] == "reverse":
        sent = reverse_ab(sent, int(oder[1]), int(oder[2]))
    else:
        sent = replace_abp(sent, int(oder[1]), int(oder[2]), oder[3])

for s in results:
    print(s)

Solution (Python):
s = input()
n = int(input())
for _ in range(n):
    O = list(map(str, input().split()))
    i = int(O[1])
    j = int(O[2])
    if O[0] == 'print':
        print(s[i:j + 1])
    elif O[0] == 'reverse':
        ss = s[i:j + 1]
        s = s[:i] + ss[::-1] + s[j + 1:]
    else:
        p = O[3]
        s = s[:i] + p + s[j + 1:]

Solution (Python):
a=input()
b=int(input())
while b>0:
    tmp=input().split(" ")
    if tmp[0]=="replace":
        a=a[:int(tmp[1])]+tmp[3]+a[int(tmp[2])+1:]
    if tmp[0]=="reverse":
        tmp2="".join(list(a)[int(tmp[1]):int(tmp[2])+1])[::-1]
        a=a[:int(tmp[1])]+tmp2+a[int(tmp[2])+1:]
    if tmp[0]=="print":
        print(a[int(tmp[1]):int(tmp[2])+1])
    b-=1

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

Solution (Python):





































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

Solution (Python):
a=input()
a=list(a)
b=int(input())
c=[]
for i in range(b):
    c.append(input().split())
    x=int(c[i][1])
    y=int(c[i][2])
    if c[i][0]=="replace":
        a[x:y+1]=c[i][3]
    elif c[i][0]=="reverse":
        z=a[x:y+1]
        z.reverse()
        a[x:y+1]=z
    else:
        w=a[x:y+1]
        print("".join(w))

Solution (Python):



def reverse(s, i, j):
    tmp = ''
    for i in range(j, i-1, -1):
        tmp += s[i]
    return s[:i] + tmp + s[j+1:]

def pprint(s, i, j):
    print(s[i:j+1])

def replace(s, i, j, r):
    tmp = s[:i] + r + s[j+1:]
    return tmp

word = input()

loop = int(input())







for i in range(loop):
    line = input().split()
    
    
    if line[0] == 'replace':
        word = replace(word, int(line[1]), int(line[2]),line[3])
    elif line[0] == 'reverse':
        word = reverse(word, int(line[1]), int(line[2]))
    elif line[0] == 'print':
        pprint(word, int(line[1]), int(line[2]))

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

Solution (Python):
string = str(input())
q = int(input())
for _ in range(q):
    
    data = input().split()
    left = int(data[1])
    right = int(data[2]) + 1
    
    if data[0] == "print":
        print(string[left:right])
        
    elif data[0] == "reverse":
        string = string[:left] + string[left:right][::-1] + string[right:]
        
    else:
        string = string[:left] + data[3] + string[right:]

Solution (Python):
string = list(input())
n = int(input())

for repeat in range(n):
    ope = input().split()

    if ope[0] == "replace":
        rep_str = list(ope[3])
        rep_ind = 0
        
        for i in range(int(ope[1]), int(ope[2])+1):
            
            string[i] = rep_str[rep_ind]
            rep_ind += 1
        
        
    elif ope[0] == "reverse":
        rev_str = []
        rev_ind = int(ope[2])
        times = 0
        for i in range(len(string)):
            rev_str.append(string[i])
        for i in range(int(ope[1]),int(ope[2])+1):
            string[i] = rev_str[rev_ind]
            rev_ind -= 1
        
    elif ope[0] == "print":
        for i in range(int(ope[1]),int(ope[2])+1):
            print(string[i],end="")
        print("")

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

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

  if command[0]=='reverse':
    a=int(command[1])
    b=int(command[2])
    s_list=list(reversed(s[a:b+1]))
    s=s[:a]+''.join(s_list)+s[b+1:]

  if command[0]=='replace':
    a=int(command[1])
    b=int(command[2])
    p=command[3]
    s=s[:a]+p+s[b+1:]

  if command[0]=='print':
    a=int(command[1])
    b=int(command[2])
    print(s[a:b+1])

Solution (Python):
s=input()
times=int(input())
for _ in range(times):
    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[:a]+s[a:b+1][::-1]+s[b+1:]
    else :
        s=s[:a]+order[3]+s[b+1:]

Solution (Python):
string = input()
num = int(input())
orders = [input().split() for _ in range(num)]

for order in orders:
    start = int(order[1])
    end = int(order[2]) + 1
    if order[0] == "reverse":
        string = string[:start] + string[start:end][::-1] + string[end:]
    elif order[0] == "replace":
        string = string[:start] + order[3] + string[end:]
    elif order[0] == "print":
        print(string[start:end])

Solution (Python):
def my_print(s: str, args: [int]) -> str:
    return s[int(args[0]): int(args[1]) + 1]


def my_reverse(s: str, args: list) -> str:
    start = int(args[0])
    end = int(args[1]) + 1
    to_reverse_string = s[start:end]
    return s[:start] + to_reverse_string[::-1] + s[end:]


def my_replace(s: str, args: list) -> str:
    start = int(args[0])
    end = int(args[1]) + 1
    return s[:start] + args[2] + s[end:]


def resolve():
    s = input()
    n = int(input())

    for _ in range(n):
        f, *args = input().split()

        if f == 'print':
            print(my_print(s, args))
        if f == 'reverse':
            s = my_reverse(s, args)
        if f == 'replace':
            s = my_replace(s, args)


resolve()

Solution (Python):
def rvrs(base, start, end):
    r = base[int(start):int(end) + 1][::-1]
    return base[:int(start)] + r + base[int(end) + 1:]
def rplc(base, start, end, string):
    return base[:int(start)] + string + base[int(end) + 1:]

ans = input()
q = int(input())
for _ in range(q):
    ORD = list(input().split())
    if ORD[0] == 'print':
        print(ans[int(ORD[1]):int(ORD[2])+1])
    elif ORD[0] == 'reverse':
        ans = rvrs(ans, int(ORD[1]), int(ORD[2]))
    elif ORD[0] == 'replace':
        ans = rplc(ans, int(ORD[1]), int(ORD[2]), ORD[3])

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

Solution (Python):
s = list(input().replace("\r", "").replace("\n", ""))
n = int(input())
for i in range(n):
    li = list(input().split())
    if li[0] == "print":
        a = int(li[1])
        b = int(li[2])
        print("".join(s[a:b+1]))
    elif li[0] == "replace":
        a = int(li[1])
        b = int(li[2])
        p = list(li[3])
        s[a:b+1] = p
    elif li[0] == "reverse":
        a = int(li[1])
        b = int(li[2])
        p = s[a:b+1]
        p.reverse()
        s[a:b+1] = p

Solution (Python):
S,Q,*C = open(0).read().split()
s = list(S)

i = 0
while i < len(C):
    cmd = C[i]
    i += 1
    if cmd == "replace":
        a = int(C[i])
        b = int(C[i+1])
        p = C[i+2]
        i += 3
        for j in range(a, b+1):
            s[j] = p[j - a]
    elif cmd == "reverse":
        a = int(C[i])
        b = int(C[i+1])
        i += 2
        r = list(reversed(s[a:b+1]))
        for j, c in enumerate(r):
            s[j + a] = c
    elif cmd == "print":
        a = int(C[i])
        b = int(C[i+1])
        i += 2
        print("".join(s[a:b+1]))
    else:
        print(cmd)
        break

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

s_array = []
for i in range(len(s)):
    s_array.append(s[i])

for i in range(n):
    order = input().split()
    if order[0] == "replace":
        first = int(order[1])
        last = int(order[2])
        for j in range(last-first+1):
            s_array[first+j] = order[3][j]
    elif order[0] == "reverse":
        a = int(order[1])
        b = int(order[2])
        buf = []
        for j in range(b, a-1, -1):
            buf.append(s_array[j])
        for j in range(b+1-a):
            s_array[a+j] = buf[j]
    elif order[0] == "print":
        a = int(order[1])
        b = int(order[2])
        for j in range(a, b+1):
            print("%s" % s_array[j], end="")
        print()

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

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

Solution (Python):
def rev(val, v1, v2):
    for i in range((v2-v1)//2 +1):
        val[v1+i], val[v2-i] = val[v2-i], val[v1+i]
    return val

def rep(val1, val2, v1, v2):
    for i in range(v2-v1):
        val1[v1+i] = val2[i]
    return val1

st = input()
lst = [i for i in st]
q = int(input())
for i in range(q):
    f = list(map(str, input().split()))
    if f[0] == 'print':
        s = ''.join(lst[int(f[1]):int(f[2])+1])
        print(s)
    elif f[0] == 'reverse':
        lst = rev(lst, int(f[1]), int(f[2]))
    elif f[0] == 'replace':
        x = [i for i in f[3]]
        lst = rep(lst, x, int(f[1]), int(f[2])+1)

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

Solution (Python):


def main():
    s = input()
    n = int(input())
    for _ in range(n):
        commands=input().split()
        if commands[0]=="replace":
            s=s[:int(commands[1])]+commands[3]+s[int(commands[2])+1:]
        elif commands[0]=="reverse":
            reverse_point=s[int(commands[1]):int(commands[2])+1]
            s=s[:int(commands[1])]+reverse_point[::-1]+s[int(commands[2])+1:]
        elif commands[0]=="print":
            print(s[int(commands[1]):int(commands[2])+1])

if __name__=="__main__":
    main()

Solution (Python):
import sys
input = sys.stdin.readline

S = input().strip()
m = int(input())

for _ in range(m):
    ope = input().strip().split()
    a, b = int(ope[1]), int(ope[2])
    if ope[0] == "print":
        print(S[a:b+1])
    elif ope[0] == "reverse":
        S = S[:a] + S[a:b+1][::-1] + S[b+1:]
    elif ope[0] == "replace":
        S = S[:a] + ope[3] + S[b+1:]

Solution (Python):
letters = input()
q = int(input())
for _ in range(q):
    words = input().split()
    command = words[0]
    a, b = map(int, words[1:3])

    if command == 'replace':
        letters = ''.join([letters[:a], words[3], letters[b+1:]])
    elif command == 'reverse':
        letters = ''.join([letters[:a ], letters[a:b+1][::-1], letters[b+1:]])
    elif command == 'print':
        print(letters[a:b+1])

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

rvs = []
i = 0
j = 0
p = []
order = []
for i in range(q):
    
    order.append(input().split())
    
    if order[i][0] == "replace":
        p = []
        p = list(order[i][3])

        for j in range(int(order[i][1]), int(order[i][2]) + 1):
            s[j] = p[j - int(order[i][1])]

    elif order[i][0] == "reverse":
        ss = "".join(s[int(order[i][1]):int(order[i][2]) + 1])
        rvs = list(ss)
        rvs.reverse()
        for j in range(int(order[i][1]), int(order[i][2]) + 1):
            s[j] = rvs[j - int(order[i][1])]
        
        
        
        

    elif order[i][0] == "print":
        ss = "".join(s)
        print("%s" % ss[int(order[i][1]):int(order[i][2]) + 1])

Solution (Python):
s = list(input())
q = int(input())
for i in range(q):
    cmd, a, b, *p = [x for x in input().split()]
    a = int(a)
    b = int(b)
    if cmd=='print':
        print(''.join(s[a:b+1]))
    if cmd=='reverse':
        stack = []
        for _ in range(b+1-a):
            stack.append(s.pop(a))
        for i in range(a, b+1):
            s.insert(i, stack.pop())
    if cmd=='replace':
        for i,c in zip(range(a,b+1), list(p[0])):
            s[i] = c

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):
word = input()

num = int(input())
for index in range(num):
    
    code = input().split()
    instruction = code[0]
    start, end  = int(code[1]), int(code[2])

    if instruction == "replace":
        word = word[:start] + code[3] + word[end+1:]
    elif instruction == "reverse":
        reversed_ch = "".join(reversed(word[start:end+1]))
        word = word[:start] + reversed_ch + word[end+1:]
    else:
        print(word[start:end+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()
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])