#include<bits/stdc++.h>
using namespace std;
stack<unsigned long long int> s;
int t,n,a[100005],p=1,bo=1,b,x,sum;
string c;
int main(){
cin>>t;
for (int i=1;i<=t;i++){
cin>>n;
while (s.size()) s.pop();
for (int j=1;j<=n;j++) {
cin>>c;
if (c=="push") {
cin>>x;
s.push(x);
}
else if (c=="query"){
if (s.size()==0) cout<<"Anguei!"<<endl;
else cout<<s.top()<<endl;
}
else if (c=="pop"){
if (s.size()==0) cout<<"Empty"<<endl;
else s.pop();
}
else cout<<s.size()<<endl;
}
}
}