x=input().split()
n=int(x[0])
m=int(x[1])
list1=[0]
for i in range (m):
a=input()
if(len(a)>9):
q=a.split(' ')
a=q[0]
p=int(q[1])
lenl=len(list1)
if a[4]=='L':
if lenl-1 == n:
print('The queue is full')
continue
list2=[p]
list1=list2+list1
print('Pushed in left: '+str(list2[0]))
if a[4]=='R':
if lenl-1 == n:
print('The queue is full')
continue
list2=[p]
list1=list1+list2
print('Pushed in right: '+str(list2[0]))
if a[4]=='e':
if lenl-1 == 0:
print('The queue is empty')
continue
k=list1[0]
if k == 0:
k=list1[1]
list1.pop(1)
else:
list1.pop(0)
print('Popped from left: '+str(k))
if a[4]=='i':
if lenl-1 == 0:
print('The queue is empty')
continue
lenth=len(list1)
k=list1[lenth-1]
if k == 0:
k=list1[lenth-2]
list1.pop(lenth-2)
else:
list1.pop(lenth-1)
print('Popped from right: '+str(k))