def main():

    s = eval(input())

    n = int(eval(input()))



    for i in range(n):

        cmds = input().split(' ')



        if 'reverse' == cmds[0]:

            a = int(cmds[1])

            b = int(cmds[2])+1



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



        if 'replace' == cmds[0]:

            a = int(cmds[1])

            b = int(cmds[2])+1

            res = cmds[3]



            s = s[:a]+res+s[b:]



        if 'print' == cmds[0]:

            a = int(cmds[1])

            b = int(cmds[2])+1



            print((s[a:b]))



if __name__ == '__main__': main()
def print_text(text, a, b):

    s = int(a)

    e = int(b)+1



    print((text[s:e]))



def reverse_text(text, a, b):

    s = int(a)

    e = int(b)+1



    return text[:s] + text[s:e][::-1] + text[e:]



def replace_text(text, a, b, p):

    s = int(a)

    e = int(b)+1



    return text[0:s] + p + text[e:]



def main():

    text = eval(input())

    q = int(eval(input()))



    for _ in range(q):

        op, *args = input().split()



        if   op == 'print':

            print_text(text, *args)

        elif op == 'reverse':

            text = reverse_text(text, *args)

        elif op == 'replace':

            text = replace_text(text, *args)



if __name__ == '__main__':

    main()

def main():
    s = eval(input())
    n = int(eval(input()))
    for i in range(n):
        cmds = input().split(" ")
        if "reverse" == cmds[0]:
            a = int(cmds[1])
            b = int(cmds[2]) + 1
            s = s[:a] + "".join(reversed(s[a:b])) + s[b:]
        if "replace" == cmds[0]:
            a = int(cmds[1])
            b = int(cmds[2]) + 1
            res = cmds[3]
            s = s[:a] + res + s[b:]
        if "print" == cmds[0]:
            a = int(cmds[1])
            b = int(cmds[2]) + 1
            print((s[a:b]))


if __name__ == "__main__":
    main()

def print_text(text, a, b):
    s = int(a)
    e = int(b) + 1
    print((text[s:e]))


def reverse_text(text, a, b):
    s = int(a)
    e = int(b) + 1
    return text[:s] + text[s:e][::-1] + text[e:]


def replace_text(text, a, b, p):
    s = int(a)
    e = int(b) + 1
    return text[0:s] + p + text[e:]


def main():
    text = eval(input())
    q = int(eval(input()))
    for _ in range(q):
        op, *args = input().split()
        if op == "print":
            print_text(text, *args)
        elif op == "reverse":
            text = reverse_text(text, *args)
        elif op == "replace":
            text = replace_text(text, *args)


if __name__ == "__main__":
    main()

+def print_text(text, a, b): +    s = int(a) +    e = int(b) + 1 +    print((text[s:e])) + + +def reverse_text(text, a, b): +    s = int(a) +    e = int(b) + 1 +    return text[:s] + text[s:e][::-1] + text[e:] + + +def replace_text(text, a, b, p): +    s = int(a) +    e = int(b) + 1 +    return text[0:s] + p + text[e:] + + -    s = eval(input()) -    n = int(eval(input())) -    for i in range(n): -        cmds = input().split(" ") -        if "reverse" == cmds[0]: -            a = int(cmds[1]) -            b = int(cmds[2]) + 1 -            s = s[:a] + "".join(reversed(s[a:b])) + s[b:] -        if "replace" == cmds[0]: -            a = int(cmds[1]) -            b = int(cmds[2]) + 1 -            res = cmds[3] -            s = s[:a] + res + s[b:] -        if "print" == cmds[0]: -            a = int(cmds[1]) -            b = int(cmds[2]) + 1 -            print((s[a:b])) +    text = eval(input()) +    q = int(eval(input())) +    for _ in range(q): +        op, *args = input().split() +        if op == "print": +            print_text(text, *args) +        elif op == "reverse": +            text = reverse_text(text, *args) +        elif op == "replace": +            text = replace_text(text, *args)