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