#include <iostream>
#include<string>
#include<cstdio>
using namespace std;
int main()
{
int num;
string s;
cin >> num >> s;
for (int i = 0; i < num;i++)
{
int num2; string str;
scanf("%d",&num2);
if (num2 == 1)
{
cin >> str;
s = s+str;
cout << s << endl;
}
if (num2 == 2)
{
int first, second;
scanf("%d %d", &first, &second);
s = s.substr(first, second);
cout << s << endl;
}
if (num2 == 3)
{
int third; string str;
cin >> third >> str;
s = s.insert(third, str);
cout << s << endl;
}
if (num2 == 4)
{
string str;
cin >> str;
printf("%d", s.find(str)==string::npos ? -1:s.find(str));
}
}
return 0;
}