#include<bits/stdc++.h>
using namespace std;
int main(){
int n,x;
char s[100*100],str[100];
scanf("%d%s",&n,s);
while(n--){
scanf("%d",&x);
if(x==1){
scanf("%s",str);
strcat(s,str);
puts(s);
}
else if(x==2){
int a,b,i;
scanf("%d%d",&a,&b)
for(i=a;i<a+b;i++)
s[i-a]=s[i];
s[b]='\0';
puts(s);
}
else if(x==3){
int a,i,lenste,lens;
scanf("%d%s",&a,str);
strcat(str,&s[a]);
s[a]='\0';
strcat(s,str);
puts(s);
}
else if(x==4){
scanf("%s",str);
char* pos=strstr(s,str);
if(pos==NULL)printf("-1\n");
else printf("%d\n",pos-s);
}
}
}