#include<iostream>
using namespace std;
typedef struct
{
int x,y;
}oxy_t;
int N,M;
int nFire, nLake, nExit;
int mapFire[30][30];
int mapLake[30][30];
int mapDiamond[30][30];
bool mapExit[30][30];
oxy_t queue[10000];
int t = -1, b = -1;
void push(oxy_t value)
{
t++;
queue[t] = value;
}
void pop(oxy_t &value)
{
b++;
value = queue[b];
}
void BFS(oxy_t pointFire)
{
push(pointFire);
mapFire[pointFire.x][pointFire.y] = 0;
}
int main()
{
int T;
cin>>T;
oxy_t startHugo;
for(int tc =1; tc <= T; tc++ )
{
int r,c;
cin>>N>>M;
cin>>startHugo.x>>startHugo.y;
cin>>nFire;
for(int i = 0; i< nFire; i++)
{
cin>>r>>c;
mapFire[r][c] = 1;
}
cin>>nLake;
for(int i =0; i< nLake; i++)
{
cin>>r>>c;
mapLake[r][c] = 1;
}
cin>>nExit;
for(int i =0; i < nExit; i++)
{
cin>>r>>c;
mapExit[r][c] = true;
}
for(int i =1; i <= N;i++)
for(int j =1; j <= M; j++)
{
cin>>mapDiamond[i][j];
}
// process
}
return 0;
}