#include<bits/stdc++.h>
#include<string.h>
using namespace std;
string strstrs;
int n,op;
int main(){
cin>>n;
cin>>strstrs;
for(int i=1;i<=n;i++){
cin>>op;
if(op==1){
string str;
cin>>str;
strstrs+=str;
cout<<strstrs<<endl;
}
if(op==2){
int a,b;
cin>>a>>b;
string str=strstrs;
strstrs="";
for(int j=a;j<=a+b;j++)
strstrs+=str[j];
cout<<strstrs<<endl;
}
if(op==3){
string str,qwq="",qaq="";
int a;
cin>>a>>str;
for(int j=0;j<a;j++)
qwq+=strstrs[j];
for(int j=a;j<strstrs.length();j++){
qaq+=strstrs[j];
}
strstrs=qwq+str+qaq;
cout<<strstrs<<endl;
}
if(op==4){
string str;
cin>>str;
if(strstrs.find(str)==-1) cout<<"-1";
else printf("%d\n",strstrs.find(str));
}
}
return 0;
}