pop(1, 0) :- write('0'), nl.
pop(X, Xp) := nl, write(), nl, X > 1, pop(Q, Qp), X is Q - 1.