Long before the days of international trade treaties, a
salesman would need to pay taxes at every border crossed. So
your task is to find the minimum number of borders that need to
be crossed when traveling between two countries. We model the
surface of Earth as a set of polygons in three dimensions
forming a closed convex 3D shape, where each polygon
corresponds to one country. You are not allowed to cross at
points where more than two countries meet.
Input
Each test case consists of a line containing , the number of countries
(),
followed by lines
containing the integers ,
describing (in order) the corners of a closed polygon
(). Then
follows a line with one integer , and then lines with queries , where and are country numbers (starting
with 1). No point will be on the line between two connected
points, and for all points. No two non-adjacent edges of
a country share a common point. The input is terminated by a
case where , which
should not be processed.
Output
For each query, output the number of borders you must cross
to go from to
.
Sample Input 1 |
Sample Output 1 |
6
4 0 0 0 0 0 1 0 1 1 0 1 0
4 1 0 0 1 0 1 1 1 1 1 1 0
4 0 0 0 1 0 0 1 0 1 0 0 1
4 0 1 0 1 1 0 1 1 1 0 1 1
4 0 0 0 0 1 0 1 1 0 1 0 0
4 0 0 1 0 1 1 1 1 1 1 0 1
2
1 2
1 3
0
|
2
1
|