#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
stack<string>s1;
stack<string>s2;
while(n--)
{
string s;
string c;
cin>>s;
if(s=="VISIT")
{
cin>>c;
while(!s2.empty())
s2.pop();
s1.push(c);
cout<<c<<endl;
}
else if(s=="BACK")
{
if(s1.empty())
{
cout<<"Ignore"<<endl;
}
else
{
s2.push(s1.top());
s1.pop();
if(!s1.empty())
{
cout<<s1.top()<<endl;
}
else
{
s1.push(s2.top());
s2.pop();
cout<<"Ignore"<<endl;
}
}
}
else
{
if(s2.empty())
cout<<"Ignore"<<endl;
else
{
cout<<s2.top()<<endl;
s1.push(s2.top());
s2.pop();
}
}
}
return 0;
}