#include <bits/stdc++.h>
using ll = long long;
using namespace std;
void solve(){
stack<ll> stk;
ll n; cin >> n;
for(ll i = 1; i <= n; i++){
string s1;cin >> s1;
if(s1 == "push"){
ll x; cin >> x;
stk.push(x);
}
if(s1 == "pop"){
if(!stk.empty()) stk.pop();
else cout << "Empty" << endl;
}
if(s1 == "query"){
if(stk.empty())cout << "Anguei!" << endl;
else{
ll put = stk.top();
cout << put << endl;
}
}
if(s1 == "size"){
ll sum = 0; sum = stk.size();
cout << sum << endl;
}
}
}
int main(){
ll _; cin >> _;
while(_--){
solve();
}
return 0;
}