Problem: Hexwamp is a strange swamp, paved with regular hexagonal dimples. Hexerpents crawling in this area are serpents adapted to the environment, consisting of a chain of regular hexagonal sections. Each section fits in one dimple.

Hexerpents crawl moving some of their sections from the dimples they are in to adjacent ones. To avoid breaking their bodies, sections that are adjacent to each other before the move should also be adjacent after the move. When one section moves, sections adjacent to it support the move, and thus they cannot move at that time. Any number of sections, as far as no two of them are adjacent to each other, can move at the same time.

You can easily find that a hexerpent can move its sections at its either end to only up to two dimples, and can move intermediate sections to only one dimple, if any.

For example, without any obstacles, a hexerpent can crawl forward twisting its body as shown in Figure C-1, left to right. In this figure, the serpent moves four of its eight sections at a time, and moves its body forward by one dimple unit after four steps of moves. Actually, they are much better in crawling sideways, like sidewinders.

<image>
Figure C-1: Crawling forward

Their skin is so sticky that if two sections of a serpent that are not originally adjacent come to adjacent dimples (Figure C-2), they will stick together and the serpent cannot but die. Two sections cannot fit in one dimple, of course. This restricts serpents' moves further. Sometimes, they have to make some efforts to get a food piece even when it is in the dimple next to their head.

<image>
Figure C-2: Fatal case

Hexwamp has rocks here and there. Each rock fits in a dimple. Hexerpents' skin does not stick to rocks, but they cannot crawl over the rocks. Although avoiding dimples with rocks restricts their moves, they know the geography so well that they can plan the fastest paths.

You are appointed to take the responsibility of the head of the scientist team to carry out academic research on this swamp and the serpents. You are expected to accomplish the research, but never at the sacrifice of any casualty. Your task now is to estimate how soon a man-eating hexerpent may move its head (the first section) to the position of a scientist in the swamp. Their body sections except for the head are quite harmless and the scientist wearing high-tech anti-sticking suit can stay in the same dimple with a body section of the hexerpent.



Input

The input is a sequence of several datasets, and the end of the input is indicated by a line containing a single zero. The number of datasets never exceeds 10.

Each dataset looks like the following.

> the number of sections the serpent has (=n)
>  x1 y1
>  x2 y2
>  ...
>  xn yn
>  the number of rocks the swamp has (=k)
>  u1 v1
>  u2 v2
>  ...
>  uk vk
>  X Y
>

The first line of the dataset has an integer n that indicates the number of sections the hexerpent has, which is 2 or greater and never exceeds 8. Each of the n following lines contains two integers x and y that indicate the coordinates of a serpent's section. The lines show the initial positions of the sections from the serpent's head to its tail, in this order.

The next line of the dataset indicates the number of rocks k the swamp has, which is a non-negative integer not exceeding 100. Each of the k following lines contains two integers u and v that indicate the position of a rock.

Finally comes a line containing two integers X and Y, indicating the goal position of the hexerpent, where the scientist is. The serpent's head is not initially here.

All of the coordinates x, y, u, v, X, and Y are between −999999 and 999999, inclusive. Two integers in a line are separated by a single space. No characters other than decimal digits, minus signs, and spaces to separate two integers appear in the input. The coordinate system used to indicate a position is as shown in Figure C-3.

<image>
Figure C-3: The coordinate system

Output

For each dataset, output a line that contains a decimal integer that indicates the minimum number of steps the serpent requires for moving its head to the goal position. Output lines should not contain any other characters.

You can assume that the hexerpent can reach the goal within 20 steps.

Example

Input

3
2 -2
2 -1
1 0
1
0 2
0 0
4
2 -2
2 -1
2 0
3 0
2
1 -1
0 2
0 0
8
-6 0
-5 0
-4 0
-3 0
-2 0
-1 0
0 0
1 0
1
-1 1
0 0
6
2 -3
3 -3
3 -2
3 -1
3 0
2 1
3
1 -1
1 0
1 1
0 0
3
-8000 4996
-8000 4997
-8000 4998
2
-7999 4999
-8001 5000
-8000 5000
8
10 -8
9 -7
9 -6
9 -5
9 -4
9 -3
9 -2
9 -1
0
0 0
0


Output

3
9
18
18
19
20

Solution (in CPP):

Solution:
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <assert.h>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;

#define X first
#define Y second

#define next first
#define dir second

int d[7][2] = {{0, -1},{1, -1},{1, 0},{0, 1},{-1, 1},{-1, 0},{0, 0}};

int n, m;
pii goal;

vector<vector<pii>> Body[9];
vector<vector<pii>> g[9];

inline int abs(const pii &d){
	if((ll)d.X*d.Y < 0) return min(abs(d.X), abs(d.Y)) + abs(d.X + d.Y);
	return abs(d.X) + abs(d.Y);
}

inline int abs(const pii &p1, const pii &p2){
	return abs(p1 - p2);
}

void enumerateState(vector<pii> &p){
	Body[p.size()].push_back(p);
	if(p.size() == 8) return;
	const pii b = p.back();
	p.emplace_back();
	REP(i, 6){
		const int x = b.X + d[i][0];
		const int y = b.Y + d[i][1];
		const pii q(x, y);
		int f = 1;
		RREP(j, (int)p.size()-2){
			if(abs(p[j], q) <= 1){
				f = 0;
				break;
			}
		}
		if(!f) continue;
		p.back() = q;
		enumerateState(p);
	}
	p.pop_back();
}

void makeGraph(){
	REPS(k, 8){
		const int n = Body[k].size();
		g[k].resize(n);
		REP(i, n)REP(j, i)REP(l, 7){
			int f = 1;
			int prev = l != 6;
			for(int q=1;q<k;q++){
				pii cur = Body[k][i][q];
				cur.X -= d[l][0];
				cur.Y -= d[l][1];
				const int dist = abs(Body[k][j][q], cur);
				if(dist > 1 || (dist == 1 && prev)){
					f = 0;
					break;
				}
				prev = dist;
			}
			if(f){
				g[k][i].emplace_back(j, l);
				g[k][j].emplace_back(i, l==6 ? l : (l+3)%6);
			}
		}
	}
}

int Rock[60][60];

struct State{
	pii pos;
	int id, cost;
	State(pii pos=pii(0, 0), int id=0, int cost=0)
		:pos(pos), id(id), cost(cost){}
};

int visited[60][60][4100];

int main(){
	ios::sync_with_stdio(false);
	vector<pii> p(1, pii(0, 0));
	enumerateState(p);
	makeGraph();
	while(cin >> n, n){
		vector<pii> body(n);
		REP(i, n) cin >> body[i].X >> body[i].Y;
		pii pos = pii(30, 30);
		memset(Rock, 0, sizeof(Rock));
		memset(visited, 0, sizeof(visited));
		cin >> m;
		REP(i, m){
			pii t;
			cin >> t.X >> t.Y; t = t - body[0] + pos;
			if(abs(t, pos) > 25) continue;
			Rock[t.X][t.Y] = 1;
		}
		cin >> goal.X >> goal.Y; goal = goal - body[0] + pos;
		RREP(i, n) body[i] = body[i] - body[0];
		auto it = find(ALL(Body[n]), body);
		if(it == Body[n].end()) assert(false);
		int state = it - Body[n].begin();
		
		visited[pos.X][pos.Y][state] = 1;
		queue<State> que;
		que.emplace(pos, state, 0);
		int ans = 20;
		while(!que.empty()){
			State s = que.front();que.pop();
			if(s.pos == goal){
				ans = s.cost;
				break;
			}
			FOR(it, g[n][s.id]){
				State t = s;
				t.id = it->next;
				t.pos.X += d[it->dir][0];
				t.pos.Y += d[it->dir][1];
				t.cost ++;
				if(t.cost + abs(t.pos, goal) >= 20 || visited[t.pos.X][t.pos.Y][t.id]) continue;
				visited[t.pos.X][t.pos.Y][t.id] = 1;
				int f = 1;
				REP(i, n) if(Rock[t.pos.X+Body[n][t.id][i].X][t.pos.Y+Body[n][t.id][i].Y]){
					f = 0;
					break;
				}
				if(f){
					que.push(t);
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}