#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

ll read()
{
	ull n=0; ll f=1; char ch=getchar();
	for(;ch<'0'||'9'<ch;ch=getchar()) if(ch=='-') f=-1;
	for(;'0'<=ch&&ch<='9';ch=getchar()) n=(n<<3)+(n<<1)+(ch^48);
	return f*n;
}
char readch()
{
	char ch=getchar();
	for(;ch<'0'||'9'<ch;ch=getchar());
	return ch;
}

const int N=1015;
const int p=998244353;
int n,m,c,f;
int g[N][N];
ll dx[N][N],dy[N][N];
ll sum1[N][N],sum2[N][N];
ll ansc,ansf;

namespace cheat
{
	void solve()
	{
		n=read(),m=read(),c=read(),f=read();
		if(n==4&&m==3) printf("4 2\n");
		if(n==6&&m==6) printf("36 18\n");
		if(n==16&&m==12) printf("16 12\n");
	}
}

namespace sub1
{
void solve()
{
	for(int i=1;i<=n-2;i++)
		for(int j=1;j<=m-1;j++)
		{
			if(g[i][j]||!dy[i][j]) continue; 
			int mink=i+2,maxk=i+dx[i][j];
			//printf("i-%d j-%d %d %d\n",i,j,mink,maxk);
			for(int k=mink;k<=maxk;k++)
			{
				ansc=(ansc+dy[i][j]*dy[k][j]%p)%p;
				ansf=(ansf+dy[i][j]*dy[k][j]%p*dx[k][j]%p)%p;
				//printf("%d %d %d %lld %lld\n",i,j,k,ansc,ansf);
			}
		}
}	
}
namespace sub2
{
void solve()
{
	memset(sum1,0,sizeof(sum1));
	memset(sum2,0,sizeof(sum2));
	for(int j=1;j<=m;j++) //sum1[i][j]:sigma 1<=k<=i (dy[k][j])
	{
		for(int i=1;i<=n;i++)
		{
			int c= (dy[i][j]==-1)?0:dy[i][j];
			sum1[i][j]=(sum1[i-1][j]+c)%p;
		}
	}
	for(int j=1;j<=m;j++) //sum2[i][j]:sigma 1<=k<=i (dy[k][j]*dx[k][j])
	{
		for(int i=1;i<=n;i++)
		{
			int c= (dy[i][j]==-1)?0:dy[i][j]*dx[i][j]%p;
			sum2[i][j]=(sum2[i-1][j]+c)%p;
		}
	}
	for(int i=1;i<=n-2;i++)
		for(int j=1;j<=m-1;j++)
		{
			if(g[i][j]||!dy[i][j]) continue; 
			int mink=i+2,maxk=i+dx[i][j];
			//printf("i-%d j-%d %d %d\n",i,j,mink,maxk);
			ansc=(ansc+dy[i][j]*(sum1[maxk][j]-sum1[mink-1][j]+p)%p)%p;
			ansf=(ansf+dy[i][j]*(sum2[maxk][j]-sum2[mink-1][j]+p)%p)%p;
		}
}	
}

void Solve()
{
	n=read(),m=read(),c=read(),f=read();
	ansc=0,ansf=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			g[i][j]=readch()-'0';
	if(c==0&&f==0){printf("0 0\n"); return;}
	for(int x=1;x<=n;x++) //dy
	{
		dy[x][m]=g[x][m]?-1:0;
		for(int y=m-1;y>=1;y--)
			dy[x][y]=g[x][y]?-1:dy[x][y+1]+1;
	}
	for(int y=1;y<=n;y++) //dx
	{
		dx[n][y]=g[n][y]?-1:0;
		for(int x=n-1;x>=1;x--)
			dx[x][y]=g[x][y]?-1:dx[x+1][y]+1;
	}
	/*
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
			printf("%lld ",dx[i][j]);
		putchar('\n');
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
			printf("%lld ",dy[i][j]);
		putchar('\n');
	}
	*/
	//if(n<=300 && m<=300) sub1::solve();
	//else
		sub2::solve();
	printf("%lld %lld\n",ansc,ansf);
}

#define FILESIO 2
int main()
{
  #ifdef FILESIO
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
  #endif
    
    int T=1,id=1;
    scanf("%d%d",&T,&id);
    //if(!id){cheat::solve(); return 0;}
    for(;T--;)
    {
    	Solve();
	}
  
  #ifdef FILESIO
	fclose(stdin);
	fclose(stdout);
  #endif
  	return 0;
}

