#include <string>
#include<iostream>
#include<iomanip>
#include<sstream>
#include<algorithm>
#include<vector>
#include<queue>
using
namespace
std;
int
main()
{
int
n;
cin>>n;
int
m;
string s;
queue<string> q;
while
(n--)
{
cin>>m;
if
(m==1)
{
cin>>s;
q.push(s);//推进队
}
else
if
(m==2)
{
if
(!q.empty())
{
cout<<q.front()<<endl;
q.pop();
}
else
cout<<
"-1"
<<endl;
}
else
if
(m==3)
{
q=queue<string>();//清除队列(赋值空)
}
}
return
0;
}