#include<bits/stdc++.h>
using namespace std;
int main(){
int q,a,b;
string shi,z,i;
cin>>q>>shi;
int ac[q];
for(int i=0;i<q;i++){
cin>>ac[i];
if(ac[i]==1){
cin>>z;
shi+=z;
cout<<shi<<endl;
}
if(ac[i]==2){
cin>>a>>b;
shi=shi.substr(a,b);
cout<<shi<<endl;
}
if(ac[i]==3){
cin>>a>>z;
shi=shi.insert(a,z);
cout<<shi<<endl;
}
if(ac[i]==4){
cin>>z;
i=shi.find(z);
if(i!=string::npos) cout<<i<<endl;
else cout<<"-1"<<endl;
return 0;
}
}
return 0;
}