public static void main (String args[]) throws Exception {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int m = Integer.parseInt(reader.readLine());

		String currentOperation;
		int currentNumber;
		boolean isSuccess;
		for (int i=0; i<m; i++) {
			isSuccess = true;
			int n = Integer.parseInt(reader.readLine());

			//ArrayStack stack = new ArrayStack();
			LinkStack stack = new LinkStack();

			for (int j=0; j<n; j++) {
				StringTokenizer st = new StringTokenizer(reader.readLine());
				if (isSuccess) {
					currentOperation = st.nextToken();
					if (currentOperation.equals("push")) {
						currentNumber = Integer.parseInt(st.nextToken());
						stack.push(currentNumber);
					} else {
						isSuccess = stack.pop();	//即使失败了也不能马上break，要把后面的命令读完
					}
				}
			}

			if (isSuccess) {
				if (stack.size() > 0) {   //栈空的时候不输出
					System.out.println(stack.toString());
				}
			} else {
				System.out.println("error");
			}
		}
	}