#include <iostream>
#include <stack>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
stack<long long> st;
for (int i = 0; i < n; i++) {
string op;
cin >> op;
if (op == "push") {
long long num;
cin >> num;
st.push_back(num);
} else if (op == "pop") {
if (st.empty()) {
cout << "Empty" << endl;
} else {
st.pop_back();
}
} else if (op == "query") {
if (st.empty()) {
cout << "Anguei!" << endl;
} else {
cout << st.back() << endl;
}
} else if (op == "size") {
cout << st.size() << endl;
}
}
}
return 0;
}