#include<stdio.h>
#include<stdlib.h>
#define maxsize 100
typedef struct{
int *base;
int front;
int rear;
} *myqueue;
void initqueue(myqueue q)
{
q->base = (int *)malloc(sizeof(int) * maxsize);
q->front = q->rear=0;
}
int push(int x,myqueue q)
{
if((q->rear+1)%maxsize==q->front)
return 0;
q->base[q->rear] = x;
q->rear = (q->rear + 1) % maxsize;
}
int pop(int *e,myqueue q)
{
if(q->front==q->rear)
return 2;
*e = q->base[q->front];
q->front = (q->front + 1) % maxsize;
}
int myqueuelength(myqueue q)
{
return ((q->rear - q->front + maxsize) % maxsize);
}
int main()
{
int n;
scanf("%d", &n);
int i, operate;
myqueue q;
initqueue(q);
for (i = 0; i < n;i++)
{
scanf("%d", &operate);
if(operate==1)
{
int x;
scanf("%d", &x);
push(x, q);
}
if(operate==2)
{
int y;
if(pop(&y,q)==2)
printf("Invalid\n");
else
printf("%d\n", y);
}
if(operate==3)
printf("%d\n", myqueuelength(q));
}
return 0;
}