#include <bits/stdc++.h>
#define nl "\n"
using namespace std;
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int len,ope;
cin >> len >> ope;
string X;
cin >> X;
for(int i=0 ; i<=ope ; i++){
string que;
cin >> que;
if(que == "substr"){
int pos1,pos2;
cin >> pos1 >> pos2;
cout << X.substr(pos1-1,pos2)<<nl;
} else if(que == "sort"){
int pos1,pos2;
cin >> pos1 >> pos2;
sort(X.begin()+pos1-1,X.begin()+pos2);
} else if(que == "pop_back"){
X.pop_back();
} else if(que == "back"){
cout << X.back()<<nl;
} else if(que == "reverse"){
int pos1,pos2;
cin >> pos1 >> pos2;
pos1 -=1;
reverse(X.begin()+pos1,X.begin()+pos2);
} else if(que == "front"){
cout << X.front()<<nl;
} else if(que == "push_back"){
char ch;
cin >> ch;
X.push_back(ch);
} else if(que == "print"){
int pos;
cin >> pos;
cout << X[pos-1] <<nl;
}
}
return 0 ;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgbmwgIlxuIgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCl7CiAgI2lmbmRlZiBPTkxJTkVfSlVER0UKICBmcmVvcGVuKCJpbnB1dC50eHQiLCJyIixzdGRpbik7CiAgZnJlb3Blbigib3V0cHV0LnR4dCIsInciLHN0ZG91dCk7CiAgI2VuZGlmCiAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygwKTsKICBjaW4udGllKDApOwogIGNvdXQudGllKDApOwoKCiAgaW50IGxlbixvcGU7CiAgY2luID4+IGxlbiA+PiBvcGU7CiAgc3RyaW5nIFg7CiAgY2luID4+IFg7CiAgZm9yKGludCBpPTAgOyBpPD1vcGUgOyBpKyspewogICAgc3RyaW5nIHF1ZTsKICAgIGNpbiA+PiBxdWU7CgogICAgaWYocXVlID09ICJzdWJzdHIiKXsKICAgICAgaW50IHBvczEscG9zMjsKICAgICAgY2luID4+IHBvczEgPj4gcG9zMjsKICAgICAgY291dCA8PCBYLnN1YnN0cihwb3MxLTEscG9zMik8PG5sOwogICAgfSBlbHNlIGlmKHF1ZSA9PSAic29ydCIpewoKICAgICAgaW50IHBvczEscG9zMjsKICAgICAgY2luID4+IHBvczEgPj4gcG9zMjsKICAgICAgc29ydChYLmJlZ2luKCkrcG9zMS0xLFguYmVnaW4oKStwb3MyKTsKICAgIH0gZWxzZSBpZihxdWUgPT0gInBvcF9iYWNrIil7CiAgICAgIFgucG9wX2JhY2soKTsKICAgIH0gZWxzZSBpZihxdWUgPT0gImJhY2siKXsKICAgICAgY291dCA8PCBYLmJhY2soKTw8bmw7CiAgICB9IGVsc2UgaWYocXVlID09ICJyZXZlcnNlIil7CiAgICAgIGludCBwb3MxLHBvczI7CiAgICAgIGNpbiA+PiBwb3MxID4+IHBvczI7CiAgICAgIHBvczEgLT0xOwogICAgICByZXZlcnNlKFguYmVnaW4oKStwb3MxLFguYmVnaW4oKStwb3MyKTsKICAgIH0gZWxzZSBpZihxdWUgPT0gImZyb250Iil7CiAgICAgIGNvdXQgPDwgWC5mcm9udCgpPDxubDsKICAgIH0gZWxzZSBpZihxdWUgPT0gInB1c2hfYmFjayIpewogICAgICBjaGFyIGNoOwogICAgICBjaW4gPj4gY2g7CiAgICAgIFgucHVzaF9iYWNrKGNoKTsKICAgIH0gZWxzZSBpZihxdWUgPT0gInByaW50Iil7CiAgICAgIGludCBwb3M7CiAgICAgIGNpbiA+PiBwb3M7CiAgICAgIGNvdXQgPDwgWFtwb3MtMV0gPDxubDsKICAgIH0KCiAgfQoKCiAgcmV0dXJuIDAgOwp9IAo=