#include <bits/stdc++.h>
#define int unsigned long long int
using namespace std;
stack<int> sk;
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int T;
cin>>T;
while(T--){
int n;
cin>>n;
while(n--){
string s;
cin>>s;
int x;
if(s=="push"){
cin>>x;
sk.push(x);
}
else if(s=="pop"){
if(!sk.empty()){
sk.pop();
}else{
puts("Empty");
}
}else if(s=="query"){
if(!sk.empty()){
cout<<sk.top()<<endl;
}else{
puts("Anguei!");
}
}else if(s=="size"){
cout<<sk.size()<<endl;
}
}
}
return 0;
}