#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <time.h>
#include <cstdlib>
#include <cstdio>
#include <cstring>
using namespace std;
long long st[1000005];
int t;
int main(){
cin>>t;
int n;
for(int i=1;i<=t;i++){
cin>>n;
string s;
int sz=0;
bool empty=true;
for(int j=1;j<=n;j++){
cin>>s;
if(s=="push"){
long long x;
cin>>x;
st[sz+1]=x;
sz++;
empty=false;
}
else if(s=="query"){
if(empty==true)
cout<<"Anguei!"<<endl;
else
cout<<st[sz]<<endl;
}
else if(s=="pop"){
if(empty==true)
cout<<"Empty"<<endl;
else{
st[sz]=0;
sz--;
if(sz<=0)
empty=true;
}
}
else
cout<<sz<<endl;
}
memset(st,0,sizeof st);
sz=0;
}
return 0;
}