#include<bits/stdc++.h>
using namespace std;
stack <int> st;
int t, n;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> t;
while (t--) {
cin >> n;
while (n--) {
string s;
cin >> s;
if (s == "Push") {
int x;
cin >> x;
st.push(x);
}
else if (s == "pop") {
if (!st.empty()) st.pop();
else cout << "Empty" << endl;
}
else if (s == "query") {
if (!st.empty()) cout << st.top() << endl;
else cout << "Anguei!";
}
else if (s == "size") {
cout << st.size();
}
}
}
while (!st.empty()) {
cout <<st.top() << " ";
st.pop();
}
return 0;
}