import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int q = Integer.parseInt(scanner.nextLine());
String currentText = scanner.nextLine();
for (int count = 0; count < q; count++) {
String operate = scanner.nextLine();
char operateCode = operate.charAt(0);
String operateParameter = operate.substring(2);
switch (operateCode) {
case '1' -> {
currentText += operateParameter;
System.out.println(currentText);
}
case '2' -> {
String[] two = operateParameter.split(" ");
int a = Integer.parseInt(two[0]), b = Integer.parseInt(two[1]);
currentText = currentText.substring(a, a + b - 1);
System.out.println(currentText);
}
case '3' -> {
String[] two = operateParameter.split(" ");
int a = Integer.parseInt(two[0]);
String str = two[1];
String currentTextLeft = currentText.substring(0, a), currentTextRight = currentText.substring(a);
currentText = currentTextLeft + str + currentTextRight;
System.out.println(currentText);
}
case '4' -> {
System.out.println(currentText.indexOf(operateParameter));
}
}
}
}
}