#include <iostream>
#include <stack>
using namespace std;

template<typename T>
class Queue2Stack
{
	stack<T> in, out;
	public:
	void push( const T& what )
	{
		while( !out.empty() )
		{
	    	in.push( out.top() );
	    	out.pop();
		}
		in.push( what );
	}
	
	T pop()
	{
		while( !in.empty() )
		{
	    	out.push( in.top() );
	    	in.pop();
		}
		T result = out.top();
		out.pop();
		return result;
	}
};

int main() {
	Queue2Stack<int> st;
	cout << "push 1, 2" << endl;
	st.push(1);
	st.push(2);
	cout << "pop " << st.pop() << endl;
	cout << "push 3, 4" << endl;
	st.push(3);
	st.push(4);
	cout << "pop " << st.pop() << ", ";
	cout << st.pop() << ", ";
	cout << st.pop() << endl;
	
	return 0;
}