The input consists of a number of datasets. Each dataset represents the way Pablo made a piece of his artwork. The format of a dataset is as follows.
N
n1 d1
n2 d2
...
nN-1 dN-1
The first line contains the number of squares (= N) used to make the piece of artwork. The number is a positive integer and is smaller than 200.
The remaining (N-1) lines in the dataset are square placement instructions. The line “ni di” indicates placement of the square numbered i (≤ N-1). The rules of numbering squares are as follows. The first square is numbered "zero". Subsequently placed squares are numbered 1, 2, ..., (N-1). Note that the input does not give any placement instruction to the first square, which is numbered zero.
A square placement instruction for the square numbered i, namely “ni di”, directs it to be placed next to the one that is numbered ni, towards the direction given by di, which denotes leftward (= 0), downward (= 1), rightward (= 2), and upward (= 3).
For example, pieces of artwork corresponding to the four datasets shown in Sample Input are depicted below. Squares are labeled by their numbers.
The end of the input is indicated by a line that contains a single zero.