s = eval(input())

n = int(eval(input()))

for _ in range(n):

    line = input().split()

    command, args = line[0], line[1:]

    start = int(args[0])

    end = int(args[1]) + 1

    if command == 'replace':

        s = s[:start] + args[2] + s[end:]

    elif command == 'reverse':

        s = s[:start] + str(''.join(list(reversed(s[start:end])))) + s[end:]

    elif command == 'print':

        print((s[start:end]))
s = eval(input())

q = int(eval(input()))

for i in range(q):

    line = eval(input())

    if 'print' in line:

        op, a, b = line.split()

        a = int(a)

        b = int(b)

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

    elif 'reverse' in line:

        op, a, b = line.split()

        a = int(a)

        b = int(b)

        reversed_substring = ''.join(list(reversed(s[a:b+1])))

        s = s[:a] + reversed_substring + s[b+1:]

    elif 'replace' in line:

        op, a, b, p = line.split()

        a = int(a)

        b = int(b)

        s = s[:a] + p + s[b+1:]



s = eval(input())
n = int(eval(input()))
for _ in range(n):
    line = input().split()
    command, args = line[0], line[1:]
    start = int(args[0])
    end = int(args[1]) + 1
    if command == "replace":
        s = s[:start] + args[2] + s[end:]
    elif command == "reverse":
        s = s[:start] + str("".join(list(reversed(s[start:end])))) + s[end:]
    elif command == "print":
        print((s[start:end]))

s = eval(input())
q = int(eval(input()))
for i in range(q):
    line = eval(input())
    if "print" in line:
        op, a, b = line.split()
        a = int(a)
        b = int(b)
        print((s[a : b + 1]))
    elif "reverse" in line:
        op, a, b = line.split()
        a = int(a)
        b = int(b)
        reversed_substring = "".join(list(reversed(s[a : b + 1])))
        s = s[:a] + reversed_substring + s[b + 1 :]
    elif "replace" in line:
        op, a, b, p = line.split()
        a = int(a)
        b = int(b)
        s = s[:a] + p + s[b + 1 :]

-n = int(eval(input())) -for _ in range(n): -    line = input().split() -    command, args = line[0], line[1:] -    start = int(args[0]) -    end = int(args[1]) + 1 -    if command == "replace": -        s = s[:start] + args[2] + s[end:] -    elif command == "reverse": -        s = s[:start] + str("".join(list(reversed(s[start:end])))) + s[end:] -    elif command == "print": -        print((s[start:end])) +q = int(eval(input())) +for i in range(q): +    line = eval(input()) +    if "print" in line: +        op, a, b = line.split() +        a = int(a) +        b = int(b) +        print((s[a : b + 1])) +    elif "reverse" in line: +        op, a, b = line.split() +        a = int(a) +        b = int(b) +        reversed_substring = "".join(list(reversed(s[a : b + 1]))) +        s = s[:a] + reversed_substring + s[b + 1 :] +    elif "replace" in line: +        op, a, b, p = line.split() +        a = int(a) +        b = int(b) +        s = s[:a] + p + s[b + 1 :]