import java.util.Scanner;

public class Main{

	static String strOrder ="";

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		//???????????????????????????
	//	System.out.println("??????????????\?????????????????????");
		String strInput = sc.nextLine();

		String[] arrayStrInput = new String[strInput.length()];

		//?????????????????????????????????????´??????????
		for(int i = 0; i < strInput.length(); i++) {
			arrayStrInput[i] = strInput.substring(i, i+1);
		}

		//????????°?????\???
	//	System.out.println("??????????????????????????\?????????????????????");
		String strNum = sc.nextLine();
		int intNum = Integer.parseInt(strNum);

	//	System.out.println(intNum);

		String[] strOrder = new String[intNum];

		//????????????????????????
		for(int i = 0; i < intNum; i++){
	//		System.out.println("??????????????\?????????????????????");
			strOrder[i] = sc.nextLine();
		}
		for(int i = 0; i < strOrder.length; i++) {

			if(strOrder[i].indexOf("print") != -1) {
	//			System.out.println("print????????????????????????");
				orders1(strOrder[i], arrayStrInput);
			}
			else if(strOrder[i].indexOf("reverse") != -1) {
	//			System.out.println("reverse????????????????????????");
				arrayStrInput = orders2(strOrder[i], arrayStrInput);
			}
			else if(strOrder[i].indexOf("replace") != -1) {
	//			System.out.println("replace????????????????????????");
				arrayStrInput = orders3(strOrder[i], arrayStrInput);
			}

		}
	//	System.out.println("??????");
	}
	public static void orders1(String strOrder, String[] arrayStrInput) {
		//System.out.println("strOrder : "+strOrder);

		Scanner sc1 = new Scanner(strOrder);
		String Order = sc1.next();
		int intNum1 = sc1.nextInt();
		int intNum2 = sc1.nextInt();

		for(int i = intNum1; i <= intNum2; i++) {
			System.out.print(arrayStrInput[i]);
		}
		System.out.println("");
		//System.out.printf("%s %d %d",Order, intNum1, intNum2);
	}
	public static String[] orders2(String strOrder, String[] arrayStrInput) {
	//	System.out.println("orders2?????????????????????");
		Scanner sc1 = new Scanner(strOrder);
		String Order = sc1.next();
		int intNum1 = sc1.nextInt();
		int intNum2 = sc1.nextInt();

		//????????????????????°????¨?????????????
		int Sum = (intNum2 - intNum1 + 1)/2;

		int intMaxNum = intNum2;
		String strOkiba ="";

		//intNum1??????Sum??? ????????????
		for(int i = 0; i < Sum; i++) {
			strOkiba = arrayStrInput[intNum1];
			arrayStrInput[intNum1] = arrayStrInput[intMaxNum];
			arrayStrInput[intMaxNum] = strOkiba;
			intNum1++;
			intMaxNum--;
		}
	//	System.out.printf("%s %d %d",Order, intNum1, intNum2);
		return arrayStrInput;
	}
	public static String[] orders3(String strOrder, String[] arrayStrInput) {
	//	System.out.println("orders3(replace)?????????????????????");
		Scanner sc1 = new Scanner(strOrder);
		String Order = sc1.next();
		int intNum1 = sc1.nextInt();
		int intNum2 = sc1.nextInt();
		String strNewWrite = sc1.next();
		String[] NewWrite = new String[strNewWrite.length()];

		for(int i = 0; i < strNewWrite.length(); i++) {
			NewWrite[i] = strNewWrite.substring(i, i+1);
		}
		int Count = 0;
		for(int i = intNum1; i <= intNum2; i++) {
			arrayStrInput[i] = NewWrite[Count];
			Count++;
		}
	//	for(String s : arrayStrInput) {
	//		System.out.println("??????????????????"+s);
	//	}
		return arrayStrInput;
		//System.out.printf("%s %d %d %s",Order, intNum1, intNum2, strNewWrite);
	}
}

Measured memory_bytes: 39868