/*
#include <stdio.h>
#include <string.h>
int stack[201]={};
int top=-1; // top : 마지막 데이터의 위치
int push(int p)
{
top++;
stack[top]=p;
}
void top1()
{
if(top==-1)
{
printf("-1\n");
}
else
{
printf("%d\n",stack[top]);
}
}
void pop()
{
if(top!=-1)
{
top--;
}
}
void size()
{
printf("%d\n",top+1);
}
void empty()
{
if(top==-1)
{
printf("true\n");
}
else
{
printf("false\n");
}
}
int main()
{
int a,b,i;
char str[101]={};
scanf("%d",&a);
for(i=1 ; i<=a ; i++)
{
scanf("%s",str);
if(str[0]=='p'&&str[1]=='u')
{
scanf("%d )",&b);
push(b);
}
else if(str[0]=='t')
{
top1();
}
else if(str[0]=='p'&&str[1]=='o')
{
pop();
}
else if(str[0]=='s')
{
size();
}
else if(str[0]=='e')
{
empty();
}
}
}
*/
#include <stdio.h>
#include <string.h>
int queue[201]={};
int front=-1;
int back=-1;
int push(int x)
{
back++;
queue[back]=x;
}
void front1()
{
if(front==back)
{
printf("-1\n");
}
else
{
printf("%d\n",queue[front+1]);
}
}
void back1()
{
if(front==back)
{
printf("-1\n");
}
else
{
printf("%d\n",queue[back]);
}
}
void pop()
{
if(back!=front)
{
front++;
}
}
void size()
{
printf("%d\n",back);
}
void empty()
{
if(front==back)
{
printf("true\n");
}
else
{
printf("false\n");
}
}
int main()
{
int a,b,i;
char str[101]={};
scanf("%d\n",&a);
for(i=1 ; i<=a ; i++)
{
scanf("%s",str);
if(str[0]=='p'&&str[1]=='u')
{
scanf("%d )",&b);
push(b);
}
else if(str[0]=='f')
{
front1();
}
else if(str[0]=='b')
{
back1();
}
else if(str[0]=='p'&&str[1]=='o')
{
pop();
}
else if(str[0]=='s')
{
size();
}
else if(str[0]=='e')
{
empty();
}
}
}