#include <bits/stdc++.h>
using namespace std;
int main()
{
int a;
cin>>a;
string b;
cin>>b;
for(int i=1;i<=a;i++)
{
int c;
cin>>c;
if(c==1)
{
string d;
cin>>d;
b=b+d;
cout<<b<<endl;
}
if(c==2)
{
int d,e;
cin>>d>>e;
b=b.substr(d,d+e);
cout<<b<<endl;
}
if(c==3)
{
int d;
string e;
cin>>d>>e;
b=b.insert(a-1,e);
cout<<b<<endl;
}
if(c==4)
{
string d;
cin>>d;
if(b.find(d)<100)
cout<<b.find(d)<<endl;
else
cout<<-1<<endl;
}
}
return 0;
}