#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string s;
cin >> s;
for(int i = 1; i <= n; i++)
{
string temp;
int j;
if(i == 1)
{
cin >> j >> temp;
s += temp;
cout << s << endl;
}
if(i == 2)
{
int start, count;
cin >> j >> start >> count;
s = s.substr(start, count);
cout << s << endl;
}
if(i == 3)
{
int index;
string temp2, temp3;
cin >> j >> index >> temp2;
temp = s.substr(index);
s = s.substr(0, index) + temp2 + temp;
cout << s << endl;
}
if(i == 4)
{
cin >> j >> temp;
int t = s.find(temp);
if(t >= 0 && t < s.size())
cout << t;
else
cout << "-1";
}
}
return 0;
}