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