#include <bits/stdc++.h>
#include <queue>
#include <string>
using namespace std;
queue<int> shapa;
int main() {
int N; cin>>N;
while (N--)
{
int k;
cin >> k;
if (k == 1) {
int x;
cin >> x;
shapa.push(x);
} else if (k == 2) {
if (!shapa.empty()) {
shapa.front();
cout << shapa.front() << endl;
} else {
cout << "-1" << endl;
}
} else if (k == 3) {
if (!shapa.empty()) {
shapa.pop();
}
}
}
return 0;
}