Origami is the ancient art of folding a single sheet of paper into shapes such as animals and flowers. A machine performs simple origami on a board with a coordinate system. A square sheet of paper is placed on the board so that its lower-left corner is at $(0, 0)$ and its upper-right corner is at $(100, 100)$.
The machine then runs a program made of several folding steps, in order. Each step is a single fold line given by two points. Facing from the first point toward the second point, the paper on the left side of the line stays in place, and the paper on the right side is folded flat on top of it (reflected across the line). After the last step, the origami consists of several layers of paper.
To hang the origami you must pierce a hole through it. Given a point, compute how many layers of paper the pierce passes through, so you can tell whether the spot is neither too thick nor too thin.
The first line contains an integer $n$ ($0 \le n \le 8$), the number of folding steps. Each of the next $n$ lines contains four real numbers $x_1\ y_1\ x_2\ y_2$, the two points $(x_1, y_1)$ and $(x_2, y_2)$ that define one fold line. The folds are applied in the given order.
The next line contains an integer $m$, the number of query points. Each of the next $m$ lines contains two real numbers $x\ y$, the coordinates of a point to pierce.
For each query point, output on its own line the number of paper layers pierced at that point.
The paper has zero thickness and folds ideally. Treat each pierce as a single point. A layer that is pierced exactly on the border of the paper or on a folded edge (within $10^{-6}$) does not count as a pierced layer.