#include<bits/stdc++.h>
#include <numeric>
using namespace std;
bool isPrame(int x)
{
if(x<2) return false;
for(int i=2;i<x/i+1;i++){
if(x%i==0) return false;
}
return true;
}
int main()
{
string sh;int n,x;string ch[102];int count=0;
cin>>n>>sh;
cin.ignore();
for(int i=0;i<n;i++){
getline(cin,ch[i]);
}
for(int i=0;i<n;i++){
if(ch[i][0]=='1'){
istringstream iss(ch[i]);string temp1;
iss>>x>>temp1;
sh+=temp1;
cout<<sh<<endl;
}else if(ch[i][0]=='2'){
int a,b;istringstream iss(ch[i]);
iss>>x>>a>>b;
sh=sh.substr(a,b);
cout<<sh<<endl;
}else if(ch[i][0]=='3'){
string temp2;
istringstream iss(ch[i]);
iss>>x>>x>>temp2;
sh=sh.insert(x,temp2);
cout<<sh<<endl;
}else if(ch[i][0]=='4'){
string temp3;
istringstream iss(ch[i]);
iss>>x>>temp3;
size_t pos=sh.find(temp3);
if(pos!=string::npos) cout<<pos<<endl;
else cout<<"-1"<<endl;
}
}
return 0;
}