s = list(input())

q = int(input())

for i in range(q):

    cmd = [s for s in input().split()]

    cmd[1] = int(cmd[1])

    cmd[2] = int(cmd[2])

    if cmd[0] == "replace":

        c = list(cmd[3])

        h = 0

        for j in range(cmd[1], cmd[2]+1):

            s[j] = c[h]

            h+=1

    elif cmd[0] == "reverse":

        k = cmd[1]

        l = cmd[2]

        while k < l:

            t = s[k]

            s[k] = s[l]

            s[l] = t

            k+=1

            l-=1

    else:

        for m in range(cmd[1], cmd[2]+1):

            print("{}".format(s[m]), end = "")



        print()

        

str = [w for w in input()]

q = int(input())

for i in range(q):

    command = [w for w in input().split()]

    command[1] = int(command[1])

    command[2] = int(command[2])

    if command[0] == "print":

        for i in range(command[1], command[2]+1):

            print(str[i], end="")

        print()

    if command[0] == "replace":

        j = command[1]

        for i in range(len(command[3])):

            str[j] = command[3][i]

            j += 1

    if command[0] == "reverse":

        r = []

        for i in range(command[2], command[1]-1, -1):

            r.append(str[i])

        i = command[1]

        for w in r:

            str[i] = w

            i += 1

s = list(input())
q = int(input())
for i in range(q):
    cmd = [s for s in input().split()]
    cmd[1] = int(cmd[1])
    cmd[2] = int(cmd[2])
    if cmd[0] == "replace":
        c = list(cmd[3])
        h = 0
        for j in range(cmd[1], cmd[2] + 1):
            s[j] = c[h]
            h += 1
    elif cmd[0] == "reverse":
        k = cmd[1]
        l = cmd[2]
        while k < l:
            t = s[k]
            s[k] = s[l]
            s[l] = t
            k += 1
            l -= 1
    else:
        for m in range(cmd[1], cmd[2] + 1):
            print("{}".format(s[m]), end="")
        print()

str = [w for w in input()]
q = int(input())
for i in range(q):
    command = [w for w in input().split()]
    command[1] = int(command[1])
    command[2] = int(command[2])
    if command[0] == "print":
        for i in range(command[1], command[2] + 1):
            print(str[i], end="")
        print()
    if command[0] == "replace":
        j = command[1]
        for i in range(len(command[3])):
            str[j] = command[3][i]
            j += 1
    if command[0] == "reverse":
        r = []
        for i in range(command[2], command[1] - 1, -1):
            r.append(str[i])
        i = command[1]
        for w in r:
            str[i] = w
            i += 1

-s = list(input()) +str = [w for w in input()] -    cmd = [s for s in input().split()] -    cmd[1] = int(cmd[1]) -    cmd[2] = int(cmd[2]) -    if cmd[0] == "replace": -        c = list(cmd[3]) -        h = 0 -        for j in range(cmd[1], cmd[2] + 1): -            s[j] = c[h] -            h += 1 -    elif cmd[0] == "reverse": -        k = cmd[1] -        l = cmd[2] -        while k < l: -            t = s[k] -            s[k] = s[l] -            s[l] = t -            k += 1 -            l -= 1 -    else: -        for m in range(cmd[1], cmd[2] + 1): -            print("{}".format(s[m]), end="") +    command = [w for w in input().split()] +    command[1] = int(command[1]) +    command[2] = int(command[2]) +    if command[0] == "print": +        for i in range(command[1], command[2] + 1): +            print(str[i], end="") +    if command[0] == "replace": +        j = command[1] +        for i in range(len(command[3])): +            str[j] = command[3][i] +            j += 1 +    if command[0] == "reverse": +        r = [] +        for i in range(command[2], command[1] - 1, -1): +            r.append(str[i]) +        i = command[1] +        for w in r: +            str[i] = w +            i += 1