#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <limits.h>
#include <string>
#include <cstring>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#define ll long long
#define dd double
#define ld long double
#define pi 3.14159265359
#define ull unsigned long long
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define el "\n"
#define Arwa ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fix(x) cout<<fixed<<setprecision(x)
using namespace std;
ll gcd(ll a,ll b) {return b==0?a:gcd(b,a%b);}
ll lcm(int a,int b) {return a/gcd(a, b)*b;}
int main()
{
Arwa
int n,q;
cin>>n>>q;
string s;
cin>>s;
while(q--)
{
string t;
cin>>t;
if(t=="substr")
{
int l,r;
cin>>l>>r;
// substr بتاخد البداية والطول يعنى هتاخد الفرق بين البداية والنهاية
cout<<s.substr(l-1,r-l+1)<<el;
}
else if(t=="sort")
{
int l,r;
cin>>l>>r;
sort(s.begin()+(l-1),s.begin()+(r));
}
else if(t=="pop_back")
s.pop_back();
else if(t=="back")
cout<<s.back()<<el;
else if(t=="reverse")
{
int l,r;
cin>>l>>r;
reverse(s.begin()+(l-1),s.begin()+r);
}
else if(t=="front")
cout<<s.front()<<el;
else if(t=="push_back")
{
char x;
cin>>x;
s.push_back(x);
}
else if(t=="print")
{
int l;
cin>>l;
cout<<s[l-1]<<el;
}
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8Y21hdGg+CiNpbmNsdWRlIDxjc3RkbGliPgojaW5jbHVkZSA8Y2N0eXBlPgojaW5jbHVkZSA8bGltaXRzLmg+CiNpbmNsdWRlIDxzdHJpbmc+CiNpbmNsdWRlIDxjc3RyaW5nPgojaW5jbHVkZSA8aW9tYW5pcD4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPHF1ZXVlPgojaW5jbHVkZSA8c2V0PgojZGVmaW5lIGxsIGxvbmcgbG9u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gICAgICAgZWxzZSBpZih0PT0ic29ydCIpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGludCBsLHI7CiAgICAgICAgICAgICAgICBjaW4+Pmw+PnI7CiAgICAgICAgICAgICAgICBzb3J0KHMuYmVnaW4oKSsobC0xKSxzLmJlZ2luKCkrKHIpKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBlbHNlIGlmKHQ9PSJwb3BfYmFjayIpCiAgICAgICAgICAgIHMucG9wX2JhY2soKTsKICAgICAgICAgICAgZWxzZSBpZih0PT0iYmFjayIpCiAgICAgICAgICAgIGNvdXQ8PHMuYmFjaygpPDxlbDsKICAgICAgICAgICAgZWxzZSBpZih0PT0icmV2ZXJzZSIpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGludCBsLHI7CiAgICAgICAgICAgICAgICBjaW4+Pmw+PnI7CiAgICAgICAgICAgICAgICByZXZlcnNlKHMuYmVnaW4oKSsobC0xKSxzLmJlZ2luKCkrcik7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZSBpZih0PT0iZnJvbnQiKQogICAgICAgICAgICBjb3V0PDxzLmZyb250KCk8PGVsOwogICAgICAgICAgICBlbHNlIGlmKHQ9PSJwdXNoX2JhY2siKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBjaGFyIHg7CiAgICAgICAgICAgICAgICBjaW4+Png7CiAgICAgICAgICAgICAgICBzLnB1c2hfYmFjayh4KTsKICAgICAgICAgICAgfQogICAgICAgICAgICBlbHNlIGlmKHQ9PSJwcmludCIpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICBpbnQgbDsKICAgICAgICAgICAgICBjaW4+Pmw7CiAgICAgICAgICAgICAgY291dDw8c1tsLTFdPDxlbDsKICAgICAgICAgICAgfSAgCiAgICAgICB9CiAgICByZXR1cm4gMDsgCn0=