#include<iostream>
using namespace std;
typedef unsigned long long ULL;
const int N=1e6+5;
string s;
ULL t,n,x,sk[N],top=0;
int main(){
scanf("%lld",&t);
while(t--){
scanf("%lld",&n);
while(n--){
cin>>s;
if(s=="push"){
scanf("%lld",&x);
sk[++top]=x;
}else if(s=="pop"){
if(top)top--;
else puts("Empty");
}else if(s=="query"){
if(top)printf("%lld\n",sk[top]);
else puts("Anguei!");
}else{
printf("%lld\n",top);
}
}top=0;
}
return 0;
}