#include <bits/stdc++.h>
using namespace std;
stack<string> s;
int o,n;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string x;
cin >> o;
string t;
for(int i = 1;i <= o;i++){
cin >> n;
for(int j = 1;j <= n;j++){
cin >> t;
if(t == "push"){
cin >> x;
s.push(x);
}else if(t == "pop"){
if(s.empty()){
cout << "Empty" <<endl;
}else{
s.pop();
}
}else if(t == "query"){
if(s.empty()){
cout << "Anguei!" <<endl;
}else{
cout << s.top() <<endl;
}
}else{
cout << s.size() <<endl;
}
}
}
return 0;
}