#include <cstdio>
#include <algorithm>
#include <queue>
#define NMAX 500
using namespace std;
const int dx[4]= {1,-1,0,0};
const int dy[4]= {0,0,1,-1};
int p,n,m,t,l,c,k,s,i,j,cod,sol,pt,timp[NMAX+10][NMAX+10],x,y,Min=1000000;
bool food[NMAX+10][NMAX+10],ok[NMAX+10][NMAX+10];
queue< pair <int,int> >q;
void lee()
{
int x,y,xx,yy;
while(!q.empty())
{
x=q.front().first;
y=q.front().second;
q.pop();
for(i=0; i<=3; ++i)
{
xx=x+dx[i];
yy=y+dy[i];
if(ok[xx][yy] && !timp[xx][yy])
{
q.push(make_pair(xx,yy));
timp[xx][yy]=timp[x][y]+1;
if(food[xx][yy])
Min=min(Min,timp[xx][yy]);
}
}
}
}
int main()
{
freopen("panda.in","r",stdin);
freopen("panda.out","w",stdout);
scanf("%d",&p);
scanf("%d%d%d",&n,&m,&t);
scanf("%d%d%d%d",&l,&c,&k,&s);
for(i=1; i<=t; ++i)
{
scanf("%d%d",&x,&y);
food[x][y]=true;
}
pt=(1<<s);
for(i=1; i<=n; ++i)
for(j=1; j<=m; ++j)
{
scanf("%d",&cod);
if(!(i==l && j==c))
if(((cod%pt)^(k%pt))==(pt-1))
{
ok[i][j]=true;
++sol;
}
}
if(p==1)
printf("%d\n",sol);
else
{
q.push(make_pair(l,c));
lee();
sol=0;
printf("%d ",Min);
for(i=1; i<=n; ++i)
for(j=1; j<=m; ++j)
if(timp[i][j]==Min && food[i][j])
++sol;
printf("%d\n",sol);
}
return 0;
}