You must simulate folding a flat square sheet of paper and then punching a single pin through the folded stack, and report how many pinholes appear on the original sheet once it is unfolded.
You are given a sequence of folding instructions followed by one pinhole position. A folding instruction is a pair of points $P$ and $Q$. The paper is folded so that $P$ comes down onto $Q$ from above: the sheet is creased along the fold line — the perpendicular bisector of segment $PQ$ — and the part of the paper on the $P$ side is turned over onto the other side. The thickness of the paper is ignored.
The folded paper is a stack of flat paper segments joined along straight hinges (creases). Each fold divides some segments into smaller ones along the fold line and turns some of them over: a segment that crosses the fold line is split, and one of the two new pieces is turned over; a segment that does not cross the fold line is either turned over whole or left as is. Which segments are turned over is decided by repeatedly applying the following rules until no further segment needs turning:
When a segment is turned over it is reflected across the fold line. After all folding instructions are carried out, the pin is pushed through every layer of paper at the pinhole position, so each layer covering that position receives one hole. Report the number of holes on the sheet when it is unfolded (equivalently, the number of paper layers covering the pinhole position in the final folded stack).
The input is a sequence of datasets. The end of the input is a line containing a single zero. Each dataset has the form
k
px1 py1 qx1 qy1
...
pxk pyk qxk qyk
hx hy
For every dataset the initial sheet is a 100 mm square; using millimetres as the unit, its corners are at $(0,0)$, $(100,0)$, $(100,100)$ and $(0,100)$. The integer $k$ is the number of folding instructions, with $1 \le k \le 10$. Each of the next $k$ lines has four integers $px_i$, $py_i$, $qx_i$, $qy_i$ separated by spaces, giving the points $P = (px_i, py_i)$ and $Q = (qx_i, qy_i)$ of the $i$-th instruction; you may assume $P \ne Q$. The instructions must be carried out in the given order. The last line has two integers $hx$ and $hy$, the position $(hx, hy)$ of the pinhole.
You may assume the following:
For each dataset, output a single line containing the number of pinholes on the unfolded sheet. No other characters may appear in the output.