#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;
int mi=min(pos1,pos2) ,ma=max(pos1,pos2);
cout << X.substr(mi-1,ma)<<nl;
} else if(que == "sort"){
int pos1,pos2;
cin >> pos1 >> pos2;
int mi=min(pos1,pos2) ,ma=max(pos1,pos2);
sort(X.begin()+mi-1,X.begin()+ma);
} 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;
int mi=min(pos1,pos2) ,ma=max(pos1,pos2);
reverse(X.begin()+mi,X.begin()+ma);
} 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+IHBvczEgPj4gcG9zMjsKICAgICAgaW50IG1pPW1pbihwb3MxLHBvczIpICxtYT1tYXgocG9zMSxwb3MyKTsKICAgICAgY291dCA8PCBYLnN1YnN0cihtaS0xLG1hKTw8bmw7CiAgICB9IGVsc2UgaWYocXVlID09ICJzb3J0Iil7CgogICAgICBpbnQgcG9zMSxwb3MyOwogICAgICBjaW4gPj4gcG9zMSA+PiBwb3MyOwogICAgICBpbnQgbWk9bWluKHBvczEscG9zMikgLG1hPW1heChwb3MxLHBvczIpOwogICAgICBzb3J0KFguYmVnaW4oKSttaS0xLFguYmVnaW4oKSttYSk7CiAgICB9IGVsc2UgaWYocXVlID09ICJwb3BfYmFjayIpewogICAgICBYLnBvcF9iYWNrKCk7CiAgICB9IGVsc2UgaWYocXVlID09ICJiYWNrIil7CiAgICAgIGNvdXQgPDwgWC5iYWNrKCk8PG5sOwogICAgfSBlbHNlIGlmKHF1ZSA9PSAicmV2ZXJzZSIpewogICAgICBpbnQgcG9zMSxwb3MyOwogICAgICBjaW4gPj4gcG9zMSA+PiBwb3MyOwogICAgICBwb3MxIC09MTsKICAgICAgaW50IG1pPW1pbihwb3MxLHBvczIpICxtYT1tYXgocG9zMSxwb3MyKTsKICAgICAgcmV2ZXJzZShYLmJlZ2luKCkrbWksWC5iZWdpbigpK21hKTsKICAgIH0gZWxzZSBpZihxdWUgPT0gImZyb250Iil7CiAgICAgIGNvdXQgPDwgWC5mcm9udCgpPDxubDsKICAgIH0gZWxzZSBpZihxdWUgPT0gInB1c2hfYmFjayIpewogICAgICBjaGFyIGNoOwogICAgICBjaW4gPj4gY2g7CiAgICAgIFgucHVzaF9iYWNrKGNoKTsKICAgIH0gZWxzZSBpZihxdWUgPT0gInByaW50Iil7CiAgICAgIGludCBwb3M7CiAgICAgIGNpbiA+PiBwb3M7CiAgICAgIGNvdXQgPDwgWFtwb3MtMV0gPDxubDsKICAgIH0KCiAgfQoKCiAgcmV0dXJuIDAgOwp9IAo=