import java.math.BigInteger;
import java.util.Scanner;
import java.util.Stack;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
long T = in.nextLong();
while (T > 0) {
Stack<BigInteger> stack = new Stack<>();
long n = in.nextLong();
for (long i = 0; i < n; i++) {
String str = in.next();
if (str.equals("push")) {
BigInteger x = in.nextBigInteger();
stack.push(x);
} else if (str.equals("pop")) {
if (stack.empty()) {
System.out.println("Empty");
} else {
stack.pop();
}
} else if (str.equals("query")) {
if (stack.empty()) {
System.out.println("Anguei!");
} else {
System.out.println(stack.peek());
}
} else {
System.out.println(stack.size());
}
}
T--;
}
}
}