#include<bits/stdc++.h>
#define int unsigned long long
using namespace std;
stack<int> s;
string str;
int T,n,x;
void Clear(){
while(!s.empty()){
s.pop();
}
}
void Push(){
cin>>x;
s.push(x);
}
void Pop(){
if(!s.empty()){
s.pop();
}
else{
cout<<"Empty"<<endl;
}
}
void Query(){
if(!s.empty()){
cout<<s.top()<<endl;
}
else{
cout<<"Anguei!"<<endl;
}
}
void Size(){
cout<<s.size()<<endl;
}
void Main(){
cin>>n;
while(n--){
cin>>str;
if(str=="push"){
Push();
}
else if(str=="pop"){
Pop();
}
else if(str=="query"){
Query();
}
else{
Size();
}
}
}
signed main(){
cin>>T;
while(T--){
Clear();
Main();
}
return 0;
}