#include<bits/stdc++.h>
using namespace std;
string s;
string str;
int main() {
int q;
cin>>q;
cin>>s;
while(q--){
int op,a,b;
cin>>op;
if(op==1){
cin>>str;
s+=str;
cout<<s<<endl;
}
if(op==2){
cin>>a>>b;
s=s.substr(a,b);
cout<<s<<endl;
}
if(op==3){
cin>>a>>str;
s.insert(a,str);
cout<<s<<endl;
}
if(op==4){
cin>>str;
for(int i=1;i<=s.size();i++){
if(s.find(str)!=NULL){
cout<<s.find(str);
break;
}
else{
cout<<"-1";
return 0;
}
}
}
}
return 0;
}