#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
int T;
cin>>T;
while (T--){
int n;
cin>>n;
stack<int> s;
for (int i=1;i<=n;i++){
string t;
cin>>t;
if (t=="push"){
int y;
cin>>y;
s.push(y);
}
else if (t=="pop"){
if (s.size()==0) cout<<"Empty\n";
else s.pop();
}
else if (t=="query"){
if (s.empty()) cout<<"Anguei!\n";
else cout<<s.top()<<"\n";
}
else {
cout<<s.size()<<"\n";
}
}
}
return 0;
}