#include <cstdio>
#include <iostream>
#include<cstring>
#include<string>
#include<deque>
using namespace std;
int main()
{
int n,m;
deque<int>d;
cin>>n>>m;
while(m--)
{
int x;string str;
cin>>str;
if(str=="pushLeft")
{
cin>>x;
if(d.size()==n)
cout<<"The queue is full\n";
else
{
d.push_front(x);
cout<<"Pushed in left: "<<x<<endl;
}
}
else if(str=="pushRight")
{
cin>>x;
if(d.size()==n)
cout<<"The queue is full\n";
else
{
d.push_back(x);
cout<<"Pushed in right: "<<x<<endl;
}
}
else if(str=="popLeft")
{
if(d.size()==0)
cout<<"The queue is empty\n";
else
{
cout<<"Popped from left: "<<d.front()<<endl;
d.pop_front();
}
}
else if(str=="popRight")
{
if(d.size()==0)
cout<<"The queue is empty\n";
else
{
cout<<"Popped from right: "<<d.back()<<endl;
d.pop_back();
}
}
}
}