#include<iostream>
#include<string>
#include<stack>
using namespace std;
stack<string> back;
stack<string> forw;
int main(){
int n;
cin>>n;
while(n--){
string cmd,url="http://www.acm.org/";
while(!back.empty())
back.pop();
while(!forw.empty())
forw.pop();
back.push(url);
while(1){
cin>>cmd;
if(cmd=="QUIT")break;
if(cmd=="VISIT"){
cin>>url;
back.push(url);
cout<<url<<endl;
while(!forw.empty()) //visit new website, empty the forward stack
forw.pop();
}
if(cmd=="BACK"){
if(back.size()==1) //top url is the current
cout<<"Ignored"<<endl;
else{
forw.push(url);
back.pop();
url=back.top();
cout<<url<<endl;
}
}
if(cmd=="FORWARD"){
if(forw.empty())
cout<<"Ignored"<<endl;
else{
url=forw.top();
forw.pop();
back.push(url);
cout<<url<<endl;
}
}
}
if(n>0)
cout<<endl;
}
return 0;
}