#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
int main()
{
int n;
cin>>n;
string s;
cin>>s;
while(n--)
{
int x;
cin>>x;
switch(x)
{
case 1:
{
string t;
cin>>t;
s += t;
cout<<s<<endl;
break;
}
case 2:
{
int a,b;
cin>>a>>b;
s = s.substr(a,b);
cout<<s<<endl;
break;
}
case 3:
{
int c;
cin>>c;
string t;
cin>>t;
s.insert(c,t);
cout<<s<<endl;
break;
}
case 4:
{
string t;
cin>>t;
if(s.find(t) < s.size())
cout<<s.find(t)<<endl;
else
cout<<-1<<endl;
break;
}
}
}
return 0;
}