s = list( eval(input( )) )

n = int( eval(input( )) )

for i in range( n ):

	cmd = input( ).split( " " )

	a = int( cmd[1] )

	b = int( cmd[2] ) + 1

	if "print" == cmd[0]:

		print(( "".join( s[ a:b ] ) ))

	elif "reverse" == cmd[0]:

		for i in reversed( s[ a:b ] ):

			s[ a ] = i

			a += 1

	elif "replace" == cmd[0]:

		for i in cmd[3]:

			s[ a ] = i

			a += 1
s = list( input( ) )

n = int( input( ) )

for i in range( n ):

	cmd = input( ).split( " " )

	a = int( cmd[1] )

	b = int( cmd[2] ) + 1

	if "print" == cmd[0]:

		print(( "".join( s[ a:b ] ) ))

	elif "reverse" == cmd[0]:

		for i, ss in enumerate( reversed( s[ a:b ] ) ):

			s[ a+i ] = ss

	elif "replace" == cmd[0]:

		for i, ss in enumerate( cmd[3] ):

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

s = list(input())
n = int(input())
for i in range(n):
    cmd = input().split(" ")
    a = int(cmd[1])
    b = int(cmd[2]) + 1
    if "print" == cmd[0]:
        print(("".join(s[a:b])))
    elif "reverse" == cmd[0]:
        for i, ss in enumerate(reversed(s[a:b])):
            s[a + i] = ss
    elif "replace" == cmd[0]:
        for i, ss in enumerate(cmd[3]):
            s[a + i] = ss

-s = list(eval(input())) -n = int(eval(input())) +s = list(input()) +n = int(input()) -        for i in reversed(s[a:b]): -            s[a] = i -            a += 1 +        for i, ss in enumerate(reversed(s[a:b])): +            s[a + i] = ss -        for i in cmd[3]: -            s[a] = i -            a += 1 +        for i, ss in enumerate(cmd[3]): +            s[a + i] = ss