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