#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
int t,k=1,n,m,x,l,r;
int a[30]; //队列已经限制小于10
char str[20];
l=r=15;//从中间开始
cin>>n>>m;
for(int i=0;i<m;i++)
{
cin>>str;
if(str[1]=='u')
{
cin>>x;
if(r-l>=n)
cout<<"The queue is full"<<endl;
else
{
if(str[4]=='L')
{
cout<<"Pushed in left: "<<x<<endl;
a[l]=x;l--;
}
else
{
cout<<"Pushed in right: "<<x<<endl;
r++;a[r]=x;
}
}
}
else
{
if(l==r)
cout<<"The queue is empty"<<endl;
else
{
if(str[3]=='L')
{
cout<<"Popped from left: "<<a[l+1]<<endl;
l++;
}
else
{
cout<<"Popped from right: "<<a[r]<<endl;
r--;
}
}
}
}
return 0;
}