#include <stdio.h>
#include <iostream>
#include <memory.h>

using namespace std;

int N;

// dir
int recur(char matrix[22][22], int x, int y, int dir)
{
    int fx = -1, fy = -1;
    int max = 0;

    if (dir != 0)
    {
        for(int i = 1; x-i >=1 && y-i >=1 ; ++i)
        {
            if ( matrix[x-i][y-i] == 1 ) break; // if white
            else if ( matrix[x-i][y-i] == 2 )
            {
                if (fx > -1 && fy > -1)
                    break;
                else
                {
                    fx = x-i;
                    fy = y-i;
                }
            }
            else if (fx > -1 && fy > -1)
            {
                matrix[fx][fy] = 0;
                int val = recur(matrix, x-i, y-i, 4) + 1;
                matrix[fx][fy] = 2;
                if (val > max) max = val;
            }
        }
    }
    if (dir != 1)
    {
        fx = fy = -1;
        for(int i = 1; x+i <= N && y-i >=1 ; ++i)
        {
            if ( matrix[x+i][y-i] == 1 ) break; // if white
            else if ( matrix[x+i][y-i] == 2 )
            {
                if (fx > -1 && fy > -1)
                    break;
                else
                {
                    fx = x+i;
                    fy = y-i;
                }
            }
            else if (fx > -1 && fy > -1)
            {
                matrix[fx][fy] = 0;
                int val = recur(matrix, x+i, y-i, 4) + 1;
                matrix[fx][fy] = 2;
                if (val > max) max = val;
            }
        }
    }
    if (dir != 2)
    {
        fx = fy = -1;
        for(int i = 1; x+i <=  N && y+i <=  N; ++i)
        {
            if ( matrix[x+i][y+i] == 1 ) break; // if white
            else if ( matrix[x+i][y+i] == 2 )
            {
                if (fx > -1 && fy > -1)
                    break;
                else
                {
                    fx = x+i;
                    fy = y+i;
                }
            }
            else if (fx > -1 && fy > -1)
            {
                matrix[fx][fy] = 0;
                int val = recur(matrix, x+i, y+i, 4) + 1;
                matrix[fx][fy] = 2;
                if (val > max) max = val;
            }
        }
    }
    if (dir != 3)
    {
        fx = fy = -1;
        for(int i = 1; x-i >=1 && y+i <= N ; ++i)
        {
            if ( matrix[x-i][y+i] == 1 ) break; // if white
            else if ( matrix[x-i][y+i] == 2 )
            {
                if (fx > -1 && fy > -1)
                    break;
                else
                {
                    fx = x-i;
                    fy = y+i;
                }
            }
            else if (fx > -1 && fy > -1)
            {
                matrix[fx][fy] = 0;
                int val = recur(matrix, x-i, y+i, 4) + 1;
                matrix[fx][fy] = 2;
                if (val > max) max = val;
            }
        }
    }

    return max;
}


void solve()
{
    cin >>  N;
    int dx,dy;
    cin >>dx>>dy;

    char matrix[22][22]; // 0 free, 1 white, 2 black

    memset(matrix,0,sizeof(matrix));

    int w,b;
    cin >> w;
    for(int i = 0; i < w; ++i)
    {
        int x,y;
        cin >> x >> y;
        matrix[x][y] = 1;
    }
    cin >> b;
    for(int i = 0; i < b; ++i)
    {
        int x,y;
        cin >> x >> y;
        matrix[x][y] = 2;
    }

    int answer = recur(matrix, dx, dy, 4);
    cout << answer;
}

int main()
{
    //fstream fin("SHADOOF.IN");
    freopen("CHECKERS.IN", "r",stdin);
    int n;
    cin >> n;

    for(int ii = 0; ii < n; ++ii)
    {
        solve();
    }

    return 0;
}
