class Stack {
public:
// Push element x onto stack.
void push(int x) {
Q.push(x);
}

// Removes the element on top of the stack.
void pop() {
int len = Q.size();
for (int i = 1; i < len; i++){
Q.push(Q.front());
Q.pop();
}
Q.pop();
}

// Get the top element.
int top() {
int len = Q.size();
for (int i = 1; i < len; i++){
Q.push(Q.front());
Q.pop();
}
int front = Q.front();
Q.push(front);
Q.pop();
return front;
}

// Return whether the stack is empty.
bool empty() {
return Q.empty();
}
private:
queue<int> Q;
};