Write a program which performs a sequence of commands to a given string $str$. The command is one of:    * print a b: print from the a-th character to the b-th character of $str$   * reverse a b: reverse from the a-th character to the b-th character of $str$   * replace a b p: replace from the a-th character to the b-th character of $str$ with p  Note that the indices of $str$ start with 0.
s=' '+input()+' '
for _ in range(int(input())):
    l=input().split()
    o=l[0]
    a=int(l[1])+1; b=int(l[2])+2
    if o=='print': print(s[a:b])
    if o=='reverse': s=s[:a]+s[b-1:a-1:-1]+s[b:]
    if o=='replace': s=s[:a]+l[3]+s[b:]
print(s.strip())
s=' '+input()+' '
for _ in range(int(input())):
    l=input().split()
    o=l[0]
    a=int(l[1])+1; b=int(l[2])+2
    if o=='print': print(s[a:b])
    if o=='reverse': s=s[:a]+s[b-1:a-1:-1]+s[b:]
    if o=='replace': s=s[:a]+l[3]+s[b:]