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):
string = input()
 
n = int(input())
 
for i in range(n):
    command = input().split()
    c_n = command[0]
    c_i1 = int(command[1])
    c_i2 = int(command[2]) + 1
    if c_n == "print":
        print(string[c_i1:c_i2])
    elif c_n == "reverse":
        string = string[:c_i1] + string[c_i1:c_i2][::-1] + string[c_i2:]
    else:
        string = string[:c_i1] + command[3] + string[c_i2:]

Solution (Python):


s = str(raw_input())
q = int(raw_input())
for i in range(q):
    line = map(str, raw_input().split())
    com = line[0]
    a = int(line[1])
    b = int(line[2])
    if com == "print":
        print s[a:b+1]
    elif com == "reverse":
        tmp = s[::-1]
        s = s[:a] + tmp[len(tmp)-b-1:len(tmp)-a] + s[b+1:]
    elif com == "replace":
        p = line[3]
        s = s[:a] + p + s[b+1:]
    else:
        print "Error"

Solution (Python):
string = input()
n = int(input())
for ser in range(n):
    order = list(input().split())
    op1 = int(order[1])
    op2 = int(order[2])
    if order[0] == 'print':
        print(string[op1: op2+1])
    elif order[0] == 'reverse':
        if op1 == 0:
            op11 = None
        else:
            op11 = op1-1
        string = string[:op1] + string[op2:op11:-1] + string[op2+1:]

    elif order[0] =='replace':
        string = string[:op1] + order[3] +string[op2+1:]

Solution (Python):
s = raw_input()
n = input()
result = []
for i in xrange(n):
    c = raw_input().split()
    a = int(c[1])
    b = int(c[2])+1

    if c[0] == 'print' :
        result.append(s[a:b])
    elif c[0] == 'reverse':
        d = s[a:b]
        s = s.replace(d,d[::-1])
    elif c[0] == 'replace':
        s = s[:a] + c[3] + s[b:]

for i in result:
    print i

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

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

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

for i in l:
    op = i[0]
    a = int(i[1])
    b = int(i[2])
    if op == "replace" :
        p = i[3]
        s = s[:a] + p + s[b+1:]
    elif op == "reverse" :
        tmp = s[a:b+1]
        s = s[:a] + tmp[::-1] + s[b+1:]
    elif op == "print" :
        print s[a:b+1]

Solution (Python):
s = input()
n = int(input())
for _ in range(n):
    in_s= input().split()
    command = str(in_s[0])
    a, b = int(in_s[1]), int(in_s[2])
    if(command == "print"):
        print(s[a:b+1])
    elif(command == "reverse"):
        s = s[:a] + s[a:b+1][::-1] + s[b+1:]
    else:
        p = str(in_s[3])
        s = s[:a] + p + s[b+1:]

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

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

Solution (Python):
in_str = raw_input()
q = input()

for i in xrange(q):
    order = raw_input().split()
    a = int(order[1])
    b = int(order[2])+1

    if order[0] == "print":
        print in_str[a:b]
    if order[0] == "reverse":
        temp_str    = in_str[a:b]
        in_str = in_str[:a] + temp_str[::-1] + in_str[b:]
    if order[0] == "replace":
        in_str = in_str[:a] + order[3] + in_str[b:]

Solution (Python):



str = list(input())
str = "".join(str)

p = int(input())

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

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

Solution (Python):













































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

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

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


for i in range(times):
    order = input().split()
    
    if order[0] == "replace":
        replace_string = order[3]
        
        count = 0
        for j in range(int(order[1]), int(order[2]) + 1):
            string[j] = replace_string[count]
            count += 1
            
        
    elif order[0] == "reverse":
        
        reverse_string = string[int(order[1]):int(order[2]) + 1]
        reverse_string.reverse()
        
        
        string = string[:int(order[1])] + reverse_string + string[int(order[2])+1:]
        
        
        
        
        
    elif order[0] == "print":
        
        print("".join(string[int(order[1]):int(order[2]) + 1]))

Solution (Python):
string = list(input())
times = int(input())
for i in range(times):
    order = input().split()
    if order[0] == "replace":
        replace_string = order[3]
        count = 0
        for j in range(int(order[1]), int(order[2]) + 1):
            string[j] = replace_string[count]
            count += 1
    elif order[0] == "reverse":
        reverse_string = string[int(order[1]):int(order[2]) + 1]
        reverse_string.reverse()
        string = string[:int(order[1])] + reverse_string + string[int(order[2])+1:]
    elif order[0] == "print":
        print("".join(string[int(order[1]):int(order[2]) + 1]))

Solution (Python):



def rev(s,a,b):
 b=b+1
 t=s[a:b]
 u=t[::-1]
 x=s[:a]
 y=s[b:]
 return x+u+y

def rep(s,a,b,w):
 b=b+1
 x=s[:a]
 y=s[b:]
 return x+w+y

s=raw_input()
n=int(raw_input())
for i in xrange(n):
 d=raw_input().split()
 a=int(d[1])
 b=int(d[2])
 if d[0]=="print":
  print s[a:b+1]
 elif d[0]=="reverse":
  s=rev(s,a,b)
 elif d[0]=="replace":
  w=d[3]
  s=rep(s,a,b,w)

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

Solution (Python):
import sys
import math

def str_input():
    S = raw_input()
    if S[len(S)-1] == "\r":
        return S[:len(S)-1]
    return S

S = str_input()
n = input()

for i in xrange(n):
    arg = str_input().split()

    arg[1] = int(arg[1]);
    arg[2] = int(arg[2]);

    if arg[0] == "print":
        print S[arg[1]:arg[2]+1]
    elif arg[0] == "reverse":
        S = S[:arg[1]] + S[arg[1]:arg[2]+1][::-1] + S[arg[2]+1:]
    elif arg[0] == "replace":
        S = S[:arg[1]] + arg[3] + S[arg[2]+1:]

Solution (Python):

string = [str(i) for i in input()]
for _ in range(int(input())):
	n = input().split()
	order = n.pop(0)
	if order == 'replace':
		string = string[:int(n[0])] + \
		[i for i in n[2]] + string[int(n[1])+1:]
	elif order == 'reverse':
		string = string[:int(n[0])] + \
		string[int(n[0]):int(n[1])+1][::-1] + \
		string[int(n[1])+1:]
	else :
		out = string[ int(n[0]) : int(n[1])+1 ]
		print(''.join(out))

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

Solution (Python):

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

def rv(s,a,b):







	tmp=s[::-1]
	news=s[:int(a)]+tmp[len(tmp)-int(b)-1:len(tmp)-int(a)]+s[int(b)+1:]
	return news
def rp(s,a,b,p):
	news=s[:int(a)]+p+s[int(b)+1:]
	return news



I=raw_input()
n=int(input())
for i in range(n):
	k=raw_input().split(" ")
	if k[0]=="replace":
		I=rp(I,k[1],k[2],k[3])
	elif k[0]=="reverse":
		I=rv(I,k[1],k[2])
	elif k[0]=="print":
		pr(I,k[1],k[2])

Solution (Python):

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

def rv(s,a,b):
	tmp=s[::-1]
	news=s[:int(a)]+tmp[len(tmp)-int(b)-1:len(tmp)-int(a)]+s[int(b)+1:]
	return news
def rp(s,a,b,p):
	news=s[:int(a)]+p+s[int(b)+1:]
	return news



I=raw_input()
n=int(input())
for i in range(n):
	k=raw_input().split(" ")
	if k[0]=="replace":
		I=rp(I,k[1],k[2],k[3])
	elif k[0]=="reverse":
		I=rv(I,k[1],k[2])
	elif k[0]=="print":
		pr(I,k[1],k[2])

Solution (Python):


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

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

def rp(s,a,b,p):
	news=s[:int(a)]+p+s[int(b)+1:]
	return news




I=raw_input()
n=int(input())
for i in range(n):
	k=raw_input().split(" ")
	if k[0]=="replace":
		I=rp(I,k[1],k[2],k[3])
	elif k[0]=="reverse":
		I=rv(I,k[1],k[2])
	elif k[0]=="print":
		pr(I,k[1],k[2])

Solution (Python):
def _print(c):
    a,b = map(int,c)
    print(s[a:b+1])
def _reverse(c):
    global s
    a,b = map(int,c)
    r = s[b-len(s):a-len(s)-1:-1]
    s = s[0:a] + r + s[b+1:]
def _replace(c):
    global s
    a,b,p = c
    a = int(a)
    b = int(b)
    s = s[0:a] + p + s[b+1:]
s = input()
n = int(input())
command = {"print":_print,"reverse":_reverse,"replace":_replace}
for i in range(n):
        c = input().split()
        command[c[0]](c[1:])

Solution (Python):
s = input()
q = int(input())
for _ in range(q):
    x = input().split()
    a, b = int(x[1]), int(x[2])
    if x[0] == 'print':
        print(s[a:b+1])
    if x[0] == 'reverse':
        s = s[:a] + ''.join(reversed(s[a:b+1])) + s[b+1:]
    if x[0] == 'replace':
        s = s[:a] + x[3] + s[b+1:]

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

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

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

for qi in range(q):
    command = input().split()

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

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

for qi in range(q):
    command= input().split()

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

    else:
        p = command[3]
        s =s[:a]+p+s[b+1:]

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

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

for qi in range(q):
    command = input().split()

    a = int(command[1])
    b = int(command[2])

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

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

for qi in range(q):
    command = input().split()
    a = int(command[1])
    b = int(command[2])
    if command[0] == 'print':
        print(s[a:b + 1])
    elif command[0] == 'reverse':
        s = s[:a] + s[a:b + 1][::-1] + s[b + 1:]
    else:
        p = command[3]
        s = s[:a] + p + s[b + 1:]

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

for qi in range(q):
    command = input().split()

    a = int(command[1])
    b = int(command[2])

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

    elif command[0] =='reverse':
        s = s[:a] + s[a:b +1][::-1]+ s[b + 1:]

    else:
        p = command[3]
        s = s[:a] + p + s[b+1:]

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

for num in range(num):
	ord = input().split()
	start = int(ord[1])
	end = int(ord[2]) + 1
	
	if ord[0] == 'replace':
		rep = list(ord[3])
		for i in range(start, end):
			str[i] = rep[i - start]
			
	elif ord[0] == 'reverse':
		temp = ''.join(str[start:end])
		rev = list(temp[::-1])
		
		for i in range(start, end):
			str[i] = rev[i - start]
	else:
		print(''.join(str[start:end]))

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

for qi in range(q):
    command = input().split()

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

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

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

Solution (Python):
str = list(input())
for _ in range(int(input())):
    cmd = input().split()
    a, b = map(int, cmd[1:3])
    if cmd[0] == 'print':
        for i in range(a, b + 1):
            print(str[i], end='')
        print('')
    if cmd[0] == 'reverse':
        str = str[:a] + list(reversed(str[a:b + 1])) + str[b + 1:]
    if cmd[0] == 'replace':
        p = cmd[3]
        str = str[:a] + list(p) + str[b + 1:]

Solution (Python):

str = raw_input()
for _ in xrange(input()):
 ops = raw_input().split()
 na = int(ops[1])
 nb = int(ops[2]) + 1
 op = ops[0]
 if op[0]=="p": print str[na:nb]
 elif op[2]=="v": str = str[:na] + "".join(reversed(str[na:nb])) + str[nb:]
 else: str = str[:na] + ops[3] + str[nb:]

Solution (Python):

str = raw_input()
for _ in xrange(input()):
 ops = raw_input().split()
 na = int(ops[1])
 nb = int(ops[2]) + 1
 op = ops[0]
 if op[0]=="p": print str[na:nb]
 elif op[2]=="v":
  t = str[na:nb]
  str = str[:na] + t[::-1] + str[nb:]
 else: str = str[:na] + ops[3] + str[nb:]

Solution (Python):

str = raw_input()
for _ in xrange(input()):
 ops = raw_input().split()
 a = int(ops[1])
 b = int(ops[2]) + 1
 op = ops[0]
 if op[0]=="p": print str[a:b]
 elif op[2]=="v": str = str[:a] + str[a:b][::-1] + str[b:]
 else: str = str[:a] + ops[3] + str[b:]

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

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

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

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

for i in range(n):
    message = raw_input().split(" ")
    a, b = int(message[1]), int(message[2])

    if message[0] == "print":
        print(s[a:b+1])
    elif message[0] == "reverse":
        s = s[:a] + s[a:b+1][::-1] + s[b+1:]
    elif message[0] == "replace":
        s = s[:a] + message[3] + s[b+1:]

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

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

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

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

Solution (Python):
inp = raw_input()
q = int(raw_input())
out = ""
for i in range(q):
    text = map(str, raw_input().split())
    if text[0] == "replace":
        inp = inp[0:int(text[1])] + text[3] + inp[int(text[2])+1:len(inp)]
    elif text[0] == "reverse":
        out = inp[0:int(text[1])]
        index = int(text[2])
        for j in range(int(text[2]) - int(text[1]) + 1):
            out += inp[index]
            index -= 1
        out += inp[int(text[2])+1:len(inp)]
        inp = out
    elif text[0] == "print":
        print inp[int(text[1]):int(text[2])+1]

Solution (Python):
s = input()
n = int(input())
for i in range(n):
 a = list(input().split())
 temp = s[int(a[1]):int(a[2])+1]
 if a[0] == 'replace':
  temp3 = a[3]
  s = list(s)
  seq = 0
  for i in range(int(a[1]), int(a[2])+1):
   s[i] = temp3[seq]
   seq += 1
  s = ''.join(s)
 elif a[0] == 'reverse':
  temp2 = temp[::-1]
  s = s.replace(temp, temp2, 1)
 elif a[0] == 'print':
  print(temp)

Solution (Python):
def text_print(text, a, b):
    print(text[a:b + 1])


def text_reverse(text, a, b):
    return text[:a] + text[a:b + 1][::-1] + text[b + 1:]


def text_replace(text, a, b, replaced_text):
    return text[:a] + replaced_text + text[b + 1:]


text = raw_input()
num = int(raw_input())

while 0 < num:
    raw = raw_input().split()
    if raw[0] == "replace":
        text = text_replace(text, int(raw[1]), int(raw[2]), raw[3])
    elif raw[0] == "reverse":
        text = text_reverse(text, int(raw[1]), int(raw[2]))
    elif raw[0] == "print":
        text_print(text, int(raw[1]), int(raw[2]))
    num -= 1

Solution (Python):
def do_transform(txt, *args):
    op = args[0]
    a = int(args[1])
    b = int(args[2])
    if op == 'print':
        print(txt[a:b+1])
        return txt
    elif op == 'reverse':
        first_part = txt[:a]
        second_part = txt[a:b+1]
        third_part = txt[b+1:]
        return first_part + second_part[::-1] + third_part
    elif op == 'replace':
        p = args[3]
        first_part = txt[:a]
        third_part = txt[b+1:]
        return first_part + p + third_part


if __name__ == '__main__':
    
    text = input()
    op_count = int(input())
    transformations = []
    for i in range(op_count):
        data = [x for x in input().split(' ')]
        transformations.append(data)

    
    for d in transformations:
        text = do_transform(text, *d)

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

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

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

Solution (Python):
s=input()
for _ in range(int(input())):
    a=input().split()
    i,j=map(int, a[1:3])
    if a[0] == "print":
        print(s[i:j+1])
    elif a[0] == "reverse":
        t1=s[0:i]
        t2=list(s[i:j+1])
        t2.reverse()
        t3=s[j+1:]
        s=t1+"".join(t2)+t3
    else:
        s=s[0:i]+a[3]+s[j+1:]

Solution (Python):


s = input()
q = int(input())

for i in range(q):
    line = input().split()
    
    if len(line) == 4:
        com,a,b,r = line
        a,b = int(a),int(b)
        s = s[:a] + r + s[b+1:]
    else:
        com,a,b = line
        a,b = int(a),int(b)
        if com == "print":
            print(s[a:b+1])
        else:
            sab = s[a:b+1]
            s = s[:a] + sab[::-1] + s[b+1:]

Solution (Python):
s = input()
n = int(input())
methods = {'print': lambda s, b, e: (s, print(s[b:e+1])),
           'reverse': lambda s, b, e: (s[:b] + s[e:b-len(s)-1:-1] + s[e+1:],),
           'replace': lambda s, b, e, r: (s[:b] + r + s[e+1:],)}
for _ in range(n):
    args = input().split(' ')
    method = args[0]
    args[1] = int(args[1])
    args[2] = int(args[2])
    s = methods[method](s, *args[1:])[0]

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

Solution (Python):
str=input()
q=eval(input())
command=[]
replace=[]
numdata=[]
for i in range(q):
    x=input()
    if 'replace' in x:
        a,b,c,d=x.split()
        replace.append(d)
        numdata.append((int(b),int(c)))
    else:
        a,b,c=x.split()
        numdata.append((int(b),int(c)))
    command.append(a)
Re=iter(replace)
for i in range(q):
    if command[i]=='print':
        print(str[numdata[i][0]:numdata[i][1]+1])
    elif command[i]=='reverse':
        temp=str[numdata[i][0]:numdata[i][1]+1]
        str=str[:numdata[i][0]]+temp[::-1]+str[numdata[i][1]+1:]
    else:
        str=str[:numdata[i][0]]+next(Re)+str[numdata[i][1]+1:]

Solution (Python):
s = input()
count = int(input())
li = ["print", "reverse", "replace"]
for i in range(count):
    exp= input().split()
    a = int(exp[1])
    b = int(exp[2])
    ind = li.index(exp[0])
    if ind == 0:
        print(s[int(a):int(b)+1])
    elif ind == 1:
        s = s[:a] + s[a:b+1][::-1] + s[b+1:]
    else:
        s = s[:a] + exp[3] + s[b+1:]

Solution (Python):
str = input()
q = int(input())
for i in range(q):
    order = list(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:]

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

for _ in range(n):
    line = input().split()
    order = line[0]
    a = int(line[1])
    b = int(line[2])
    p = line[3] if len(line) == 4 else ''

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

Solution (Python):
s = input()
n = int(input())
 
for _ in range(n):
    line = input().split()
    order = line[0]
    a = int(line[1])
    b = int(line[2])
    p = line[3] if len(line) == 4 else ''
 
    if order == 'print':
        print(s[a:b+1])
    elif order == 'reverse':
        s = s[:a] + s[a:b+1][::-1] + s[b+1:]
    elif order == 'replace':
        s = s[:a] + p + s[b+1:]

Solution (Python):
str = input()
for q in range(int(input())):
    com, *num = input().strip().split()
    a, b = int(num[0]), int(num[1])
    if com == 'print':
        print(str[a:b+1])
    elif com == 'replace':
        if b == len(str)-1:
            str = str[:a] + num[2]
        else:
            str = str[:a] + num[2] + (str[b+1:])
    else: 
        if a == 0:
            str = str[b::-1] + str[b+1:]
        elif b == len(str)-1:
            str = str[:a] + str[:a-1:-1]
        else:
            str = str[:a] + str[b:a-1:-1] + str[b+1:]

Solution (Python):
str = input()
for q in range(int(input())):
    com, *num = input().strip().split()
    a, b = int(num[0]), int(num[1])
    if com == 'print':
        print(str[a:b+1])
    elif com == 'replace':
        str = str[:a] + num[2] + str[b+1:]
    else: 
        str = str[:a] + str[a:b+1][::-1] + str[b+1:]

Solution (Python):
S = raw_input()
n = int(raw_input())

for i in range(n):
    command = (raw_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])
        T = S[a:b+1]
        S = S[0:a] + T[::-1] + S[b+1:]
    else:
        a = int(command[1])
        b = int(command[2])
        S = S[0:a] + command[3] + S[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 = list(str(input()))
q = int(input())
o = ['']*q
for i in range(q):
    o[i] = str(input())
    
for i in range(q):
    order = o[i].split(' ')
    if order[0] == 'print':
        a,b = int(order[1]),int(order[2])
        for i in range(a,b+1):
            print(s[i],end = '')
        print('')

    elif order[0] == 'reverse':
        a,b = int(order[1]),int(order[2])
        tmp = s[a:b+1]
        tmp.reverse()
        s[a:b+1] = tmp        
        
    elif order[0] == 'replace':
        a,b,p = int(order[1]),int(order[2]),list(order[3])
        for i in range(b-a+1):
            s[a+i] = p[i]

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

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

Solution (Python):
'''
ITP-1_9-D
 ???????????????
????????? strstr ?????????????????????????????????????????????????????????????????°???????????????????????????????????????????????\?????????????????????????????§??????
print a b: strstr ??? a ??????????????? b ??????????????§??????????????????
reverse a b: strstr ??? a ??????????????? b ??????????????§?????????????????????
replace a b p: strstr ??? a ??????????????? b ??????????????§??? p ?????????????????????
????????§??????????????? strstr ????????????????????? 0 ???????????¨????????????
???Input
1 ?????????????????? strstr ????????????????????????strstr ?????±?°????????????????????????????2 ????????????????????° qq ????????????????????????
?¶???? qq ??????????????????????¨??????¢?????§?????????????????????
???Output
??? print ???????????¨???????????????????????????????????????????????????
'''

string = input()
exeCnt = int(input())

for cnt0 in range(exeCnt):
    exeData = input().split()
    exe00 = exeData[0]
    exe01 = int(exeData[1])
    exe02 = int(exeData[2])


    if exe00 == 'print':
        print(string[exe01:exe02 + 1])

    elif exe00 == 'reverse':
        string = string[0:exe01] + string[exe01:exe02 + 1][::-1] + string[exe02 + 1:]

    elif exe00 == 'replace':
        exe03 = exeData[3]
        string = string[0:exe01] + exe03 + string[exe02 + 1:]

Solution (Python):
'''
ITP-1_9-D
 ???????????????
????????? strstr ?????????????????????????????????????????????????????????????????°???????????????????????????????????????????????\?????????????????????????????§??????
print a b: strstr ??? a ??????????????? b ??????????????§??????????????????
reverse a b: strstr ??? a ??????????????? b ??????????????§?????????????????????
replace a b p: strstr ??? a ??????????????? b ??????????????§??? p ?????????????????????
????????§??????????????? strstr ????????????????????? 0 ???????????¨????????????
???Input
1 ?????????????????? strstr ????????????????????????strstr ?????±?°????????????????????????????2 ????????????????????° qq ????????????????????????
?¶???? qq ??????????????????????¨??????¢?????§?????????????????????
???Output
??? print ???????????¨???????????????????????????????????????????????????
'''

string = input()
exeCnt = int(input())

for cnt0 in range(exeCnt):
    exeData = input().split()
    exe00 = exeData[0]
    exe01 = int(exeData[1])
    exe02 = int(exeData[2])


    if exe00 == 'print':
        print(string[exe01:exe02 + 1])

    elif exe00 == 'reverse':
        string = string[0:exe01] + string[exe01:exe02 + 1][::-1] + string[exe02 + 1:]

    elif exe00 == 'replace':
        exe03 = exeData[3]
        string = string[0:exe01] + exe03 + string[exe02 + 1:]

Solution (Python):
s = input()
q = int(input())
for i in range(q):
    inp = input().split()
    order = inp[0]
    params = inp[1:]
    if order == "print":
        a,b = map(int,params)
        print(s[a:b+1])
    elif order == "reverse":
        a,b = map(int,params)
        s = s[:a] + s[a:b+1][::-1] + s[b+1:]
    elif order == "replace":
        a,b,p = params
        a = int(a)
        b = int(b)
        s = s[:a] + p  + s[b+1:]