#include<bits/stdc++.h>
typedef unsigned long long int ll;
typedef double db;
using namespace std;
ll T,n,x;
stack <ll> q;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
std::cin>>T;
while(T--){
std::cin>>n;
string s;
for(ll i=1;i<=n;i++){
std::cin>>s;
if(s=="push"){
std::cin>>x;
q.push(x);
}else{
if(s=="query"){
if(q.size()!=0){
cout<<q.top()<<"\n";
}else{
cout<<"Anguei!\n";
}
}else{
if(s=="pop"){
if(q.size()!=0){
q.pop();
}else{
cout<<"Empty\n";
}
}else{
cout<<q.size()<<"\n";
}
}
}
}
}
return 0;
}