#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <assert.h>

using namespace std;
#define BLACK -1
#define WHITE 1

int map[512][512];

int dx[]={1,  1, -1, -1};
int dy[]={1, -1, -1,  1};

int solve(int x, int y, int n, int prevDirection)
{
	int ans = 0;

	for(int i=0; i<4; i++)
	{
		if (abs(prevDirection-i) == 2 ) continue;

		int cx = x + dx[i], cy = y + dy[i];

		int found = false;
		while(cx > -1 && cy > -1 && cx < n && cy < n)
		{
			if (map[cx][cy] == BLACK)			
			{
				found = true;
				break;
			}

			if (map[cx][cy] == WHITE)			
			{
				break;
			}

			cx += dx[i];
			cy += dy[i];
		}

		if (found)
		{
			int bx = cx;
			int by = cy;
			map[bx][by] = 0;

			cx += dx[i];
			cy += dy[i];

			while(cx > -1 && cy > -1 && cx < n && cy < n && map[cx][cy] == 0)
			{
				int s = solve(cx, cy, n, i);
				ans = max(s + 1, ans);

				cx += dx[i];
				cy += dy[i];
			}

			map[bx][by] = BLACK;
		}
	}

	return ans;
}

bool check_position(int x, int y, int n)
{
	if (x<1 || x>n) return false;
	if (y<1 || y>n) return false;
	if ((x+y)%2 == 0) return false;
	return true;
}

int main()
{
	freopen("checkers.in", "r", stdin);
	freopen("checkers.out", "w", stdout);
	
	int test;
	cin >> test;
	
	int iter = 0;

	while(test--)
	{
		iter++;
		
		
		int n;
		cin >> n;
		assert(n>=4 && n<=20);

		int x0, y0;
		cin >> x0 >> y0;

		assert(check_position(x0, y0, n));

		memset(map, 0, sizeof(map));

		if (iter == 8)
		{
			int qwe = 0;
		}

		int w;
		cin >> w;
		assert(w >=1);
		for(int i=0; i<w; i++)
		{
			int x, y;
			cin >> x >> y;
			assert(check_position(x, y, n));
			assert(x != x0 || y != y0);
			assert(map[x-1][y-1]==0);
			map[x-1][y-1] = WHITE;			
		}

		int b;
		cin >> b;
		assert(b >=1);
		for(int i=0; i<b; i++)
		{
			int x, y;
			cin >> x >> y;
			assert(check_position(x, y, n));
			assert(x != x0 || y != y0);
			assert(map[x-1][y-1]==0);
			map[x-1][y-1] = BLACK;
			
		}

		assert(w+b+1 <= (n*n)/2);

		int res = solve(x0-1, y0-1, n, -10);					
		cout << res << endl;		
	}

	return 0;
}
