#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
stack<ll> stk;
int main(){
ll T,n;
cin>>T;
while(T--){
cin>>n;
for(ll i=1;i<=n;i++){
string ops;
cin>>ops;
if(ops=="push"){
int opd;
cin>>opd;
stk.push(opd);
}else{
if(ops=="pop"){
if(stk.size()>0){
stk.pop();
}else{
cout<<"Empty"<<endl;
}
}else if(ops=="query"){
if(stk.size()>0){
cout<<stk.top()<<endl;
}else{
cout<<"Anguei!"<<endl;
}
}else if(ops=="size"){
cout<<stk.size()<<endl;
}
}
}
stack<ll>().swap(stk);
}
return 0;
}