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