Hexerpents of Hexwamp

No attempts yetTime limit10sMemory limit128 MB

Problem

Hexwamp is a strange swamp paved with regular hexagonal dimples. A hexerpent is a serpent adapted to this environment: its body is a chain of regular hexagonal sections, and each section fits exactly into one dimple. Two sections that are consecutive in the chain always lie in adjacent dimples.

A hexerpent crawls by moving some of its sections, each from the dimple it occupies to an adjacent dimple. The body must not break, so two sections that are adjacent before a move must still be adjacent after it. When a section moves, the sections next to it in the chain support the move and therefore cannot move at the same time. Any number of sections may move simultaneously, as long as no two of the moving sections are adjacent to each other.

As a consequence, a section at either end of the serpent (the head or the tail) can move to at most two dimples, while an intermediate section can move to at most one dimple, if it can move at all.

For example, with no obstacles a hexerpent can crawl forward by twisting its body as shown in Figure C-1 (read left to right). There the serpent moves four of its eight sections at a time and advances by one dimple after four such steps. In fact hexerpents are even better at crawling sideways, like sidewinders.

Figure C-1: Crawling forward

Figure C-1: Crawling forward

Their skin is so sticky that if two sections that are not consecutive in the chain ever come to lie in adjacent dimples (Figure C-2), they stick together and the serpent dies. Two sections can never occupy the same dimple either. These rules restrict the serpent's moves; sometimes it must make an effort to reach a food piece even when the food is in the dimple right next to its head.

Figure C-2: Fatal case

Figure C-2: Fatal case

Hexwamp also has rocks here and there, each filling one dimple. A hexerpent's skin does not stick to rocks, but a section can never enter a dimple that holds a rock. Avoiding rocks restricts the moves further, but the serpents know the terrain so well that they always plan the fastest path.

You lead a team of scientists studying this swamp and its serpents, and you must complete the research without any casualties. Your task is to estimate how soon a man-eating hexerpent could move its head (the first section) to the dimple where a scientist stands. Only the head is dangerous; a scientist in a high-tech anti-sticking suit can safely share a dimple with any body section other than the head.

Input

The input is a sequence of datasets. It ends with a line containing a single zero. The number of datasets is at most $10$.

Each dataset has the following form:

n
x1 y1
x2 y2
...
xn yn
k
u1 v1
u2 v2
...
uk vk
X Y

The first line gives an integer $n$ ($2 \le n \le 8$), the number of sections of the hexerpent. Each of the next $n$ lines gives the coordinates $x$ and $y$ of one section, listed from the head to the tail in this order.

The next line gives the number of rocks $k$ ($0 \le k \le 100$). Each of the next $k$ lines gives the coordinates $u$ and $v$ of one rock.

The last line gives two integers $X$ and $Y$, the goal dimple where the scientist stands. The serpent's head does not start there.

All coordinates $x$, $y$, $u$, $v$, $X$, and $Y$ are integers between $-999999$ and $999999$, inclusive. The two integers on a line are separated by a single space. The coordinate system is the one shown in Figure C-3.

Figure C-3: The coordinate system

Figure C-3: The coordinate system

Output

For each dataset, output a single line containing one integer: the minimum number of steps the serpent needs to move its head to the goal dimple. The line must contain nothing else. You may assume that the head can always reach the goal within $20$ steps.