#include<bits/stdc++.h>
using namespace std;
string a,b;
void one(string b){
a.append(b);
cout << a << endl;
}
void two(int j,int k){
a = a.substr(j,k);
cout << a << endl;
}
void three(int k,string b){
a.insert(k,b);
cout << a << endl;
}
void four(string b){
cout << a.find(b) << endl;
}
int main(){
int n,x,j,k;
cin >> n;
cin >> a;
for(int i = 1;i <= n;i++){
cin >> x;
if(x == 1){
cin >> b;
one(b);
}
if(x == 2){
cin >> j >> k;
two(j,k);
}
if(x == 3){
cin >> k;
cin >> b;
three(k,b);
}
if(x == 4){
cin >> b;
four(b);
}
}
return 0;
}