#include <bits/stdc++.h>
using namespace std;
unsigned long long t, n, x;
string s;
stack<int>st;
int main() {
cin >> t;
while (t--) {
cin >> n;
while (n--) {
cin >> s;
if (s[2] == 's') {
cin >> x;
st.push(x);
}
if (s[1] == 'o') {
if (st.empty())
cout << "Empty" << endl;
else
st.pop();
}
if (s[0] == 'q') {
if (st.empty())
cout << "Anguei!" << endl;
else
cout << st.top() << endl;
}
if (s[0] == 's')
cout << st.size() << endl;
}
while (!st.empty()) {
st.pop();
}
}
return 0;
}