#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ss string
#define db double
#define endl '\n'
#define pi 3.1415927
#define outd fixed << setprecision(6)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
const int N=1e6;
int main() {
IOS
deque<int> dq;
int q;
cin>>q;
while(q--) {
ss s;
cin>>s;
if(s=="toFront") {
int x; cin>>x;
dq.push_front(x);
}
else if(s=="push_back") {
int x; cin>>x;
dq.push_back(x);
}
else if(s=="front") {
if(dq.empty()) {
cout<<"No job for Ada?\n";
}
else {
cout<<dq.front()<<endl;
}
}
else if(s=="back") {
if(dq.empty()) {
cout<<"No job for Ada?\n";
}
else {
cout<<dq.back()<<endl;
}
}
else if(s=="reverse") {
reverse(all(dq));
}
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgSU9TICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKDApO2Npbi50aWUoMCk7Y291dC50aWUoMCk7CiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgc3Mgc3RyaW5nCiNkZWZpbmUgZGIgZG91YmxlCiNkZWZpbmUgZW5kbCAnXG4nCiNkZWZpbmUgcGkgMy4xNDE1OTI3CiNkZWZpbmUgb3V0ZCBmaXhlZCA8PCAgc2V0cHJlY2lzaW9uKDYpCiNkZWZpbmUgYWxsKHgpICh4KS5iZWdpbigpLCAoeCkuZW5kKCkKI2RlZmluZSByYWxsKHgpICh4KS5yYmVnaW4oKSwgKHgpLnJlbmQoKQp1c2luZyBuYW1lc3BhY2UgIHN0ZDsKY29uc3QgaW50IE49MWU2OwppbnQgbWFpbigpIHsKICAgIElPUwogICAgZGVxdWU8aW50PiBkcTsKICAgIGludCBxOwogICAgY2luPj5xOwogICAgd2hpbGUocS0tKSB7CiAgICAgICAgc3MgczsKICAgICAgICBjaW4+PnM7CiAgICAgICAgaWYocz09InRvRnJvbnQiKSB7CiAgICAgICAgICAgIGludCB4OyBjaW4+Png7CiAgICAgICAgICAgIGRxLnB1c2hfZnJvbnQoeCk7CiAgICAgICAgfQogICAgICAgICBlbHNlIGlmKHM9PSJwdXNoX2JhY2siKSB7CiAgICAgICAgICAgIGludCB4OyBjaW4+Png7CiAgICAgICAgICAgIGRxLnB1c2hfYmFjayh4KTsKICAgICAgICB9CiAgICAgICBlbHNlIGlmKHM9PSJmcm9udCIpIHsKICAgICAgICAgICAgaWYoZHEuZW1wdHkoKSkgewogICAgICAgICAgICAgICAgY291dDw8Ik5vIGpvYiBmb3IgQWRhP1xuIjsKICAgICAgICAgICAgfQogICAgICAgICAgICBlbHNlIHsKICAgICAgICAgICAgY291dDw8ZHEuZnJvbnQoKTw8ZW5kbDsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgZWxzZSBpZihzPT0iYmFjayIpIHsKICAgICAgICAgICAgaWYoZHEuZW1wdHkoKSkgewogICAgICAgICAgICAgICAgY291dDw8Ik5vIGpvYiBmb3IgQWRhP1xuIjsKICAgICAgICAgICAgfQogICAgICAgICAgICBlbHNlIHsKICAgICAgICAgICAgY291dDw8ZHEuYmFjaygpPDxlbmRsOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgZWxzZSBpZihzPT0icmV2ZXJzZSIpIHsKICAgICAgICAgICAgcmV2ZXJzZShhbGwoZHEpKTsKICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gMDsKfQoK