//C++版代码
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    string s;
    int n;
    cin >> s >> n;
    while (n--) {
        string command;
        cin >> command;
        int flag = command[0] - '0';
        int i = command[1] - '0';
        int len = command[2] - '0';
        if (flag) s.replace(i, len, command.substr(3));
        else reverse(s.begin() + i, s.begin() + i + len);
        cout << s << endl;
    }
    return 0;
}
//Java版代码
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int n = sc.nextInt();
        while (n-- > 0) {
            String command = sc.next();
            int flag = command.charAt(0) - '0';
            int i = command.charAt(1) - '0';
            int len = command.charAt(2) - '0';
            if (flag == 1) s = s.substring(0,
                                               i) + command.substring(3) + s.substring(i + len);
            else s = s.substring(0, i) + reverse(s.substring(i,
                                                     i + len)) + s.substring(i + len);
            System.out.println(s);
        }
    }
    private static String reverse(String s) {
        StringBuilder sb = new StringBuilder(s);
        for (int i = 0; i < sb.length() / 2; i++) {
            char temp = sb.charAt(i);
            sb.setCharAt(i, sb.charAt(sb.length() - 1 - i));
            sb.setCharAt(sb.length() - 1 - i, temp);
        }
        return sb.toString();
    }
}
//Python版代码
s = input()
for _ in range(int(input())):
    command = input()
    flag, i, len = map(int, command[:3])
    if flag == 0:
        s = s[:i] + s[i:i + len][::-1] + s[i + len:]
    else:
        s = s[:i] + command[3:] + s[i + len:]
    print(s)