import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;

public class QuestionOne {
	public static void main(String[] args) {
		Queue<Integer> q = new LinkedList<Integer>();
		Stack<Integer> s1 = new Stack<Integer>();
		Stack<Integer> s2 = new Stack<Integer>();
		
		// Draw contents after these 3 statements
		s1.push(new Integer(3));
		s1.push(new Integer(2));
		s1.push(new Integer(1));
		
		// Draw contents after each iteration
		while (!s1.empty()) {
			s2.push(s1.pop());
			if (!s1.isEmpty()) s2.push(s1.peek());
			q.offer(s2.peek());
		}
		
		// Draw contents after this statement
		s1.push(q.remove());
		
		// Print out the contents of the stacks and queue
		String output = "";
		while (s1.size() > 0)
			output = s1.pop() + " " + output;
		System.out.println("S1 : " + output + "(top)");
		
		output = "";
		while (s2.size() > 0)
			output = s2.pop() + " " + output;
		System.out.println("S2 : " + output + "(top)");
		
		output = "";
		while (q.size() > 0)
			output = output + " " + q.remove();
		System.out.println("Q : (head)" + output);
	}

}
