text = eval(input())

count = int(eval(input()))



for c in range(count):

    args = input().split()

    (a, b) = [int(x) for x in args[1:3]]

    if args[0] == 'print':

        print((text[a:b + 1]))

    elif args[0] == 'reverse':

        text = text[0:a] + text[a:b + 1][::-1] + text[b + 1:]

    elif args[0] == 'replace':

        text = text[0:a] + args[3] + text[b + 1:]
s = eval(input())

q = int(eval(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:]
text = eval(input())
count = int(eval(input()))
for c in range(count):
    args = input().split()
    (a, b) = [int(x) for x in args[1:3]]
    if args[0] == "print":
        print((text[a : b + 1]))
    elif args[0] == "reverse":
        text = text[0:a] + text[a : b + 1][::-1] + text[b + 1 :]
    elif args[0] == "replace":
        text = text[0:a] + args[3] + text[b + 1 :]

s = eval(input())
q = int(eval(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 :]

-text = eval(input()) -count = int(eval(input())) -for c in range(count): -    args = input().split() -    (a, b) = [int(x) for x in args[1:3]] -    if args[0] == "print": -        print((text[a : b + 1])) -    elif args[0] == "reverse": -        text = text[0:a] + text[a : b + 1][::-1] + text[b + 1 :] -    elif args[0] == "replace": -        text = text[0:a] + args[3] + text[b + 1 :] +s = eval(input()) +q = int(eval(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 :]