import java.util.ArrayDeque;
import java.util.Deque;
public class Main {
public static void main(String args[]) {
Deque stack = new ArrayDeque();
Deque queue = new ArrayDeque();
stack.push("A");
stack.push("B");
stack.push("C");
stack.push("D");
while (!stack.isEmpty())
System.out.print(stack.pop() + " ");
queue.add("A");
queue.add("B");
queue.add("C");
queue.add("D");
while (!queue.isEmpty())
System.out.print(queue.remove() + " ");
}
}