#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
stack<ll> s;
string str;
ll T,n,x;
int main(){
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
cin >> T;
while(T--){
cin >> n;
while(n--){
cin >> str;
if(str[0]=='p'&&str[1]=='u'){
cin >> x;
s.push(x);
}
if(str[0]=='p'&&str[1]=='o'){
if(s.empty()) cout << "Empty\n";
else s.pop();
}
if(str[0]=='q'){
if(s.empty()) cout << "Anguei!\n";
else cout << s.top() << endl;
}
if(str[0]=='s') cout << s.size() << endl;
//cout << endl;
}
}
return 0;
}