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