#include<bits/stdc++.h>
#define int long long
using namespace std;
int t,id,n,m,c,f,sum1[1001][1001],sum2[1001][1001],bl[1001],ans1,ans2;
char a[1001][1001];
const int mod=998244353;
int write()
{
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='-')
		f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}
signed main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	t=write();
	id=write();
	while(t--)
	{
		ans1=0,ans2=0;
		n=write();m=write();c=write();f=write();
		if(c==0&&f==0)
		{
			printf("0 0\n");
			continue;
		}
		for(int i=1;i<=n;i++)
		scanf("%s",a[i]+1);
		for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		sum1[i][j]=sum1[i][j-1]+a[i][j]-'0';
		for(int j=1;j<=m;j++)
		for(int i=1;i<=n;i++)
		sum2[i][j]=sum2[i-1][j]+a[i][j]-'0';
		for(int j=1;j<=m;j++)
		{
			for(int i=1;i<=n;i++)
			if(a[i][j]=='0')
			{
				int cnt=0,l=i,r=n;
				while(l<=r)
				{
					int mid=(l+r)>>1;
					if(sum2[mid][j]-sum2[i][j]==0)
					{
						cnt=mid;
						l=mid+1;
					}
					else
					r=mid-1;
				}
				if(cnt-i+1<=2)
				{
					i=cnt+1;
					continue;
				}
				for(int k=i;k<=cnt;k++)
				{
					l=j,r=m;
					int cnt2=0;
					while(l<=r)
					{
						int mid=(l+r)>>1;
						if(sum1[k][mid]-sum1[k][j]==0)
						{
							cnt2=mid;
							l=mid+1;
						}
						else
						r=mid-1;
					}
					bl[k]=cnt2-j;
				}
				for(int k=i;k<=cnt;k++)
				if(bl[k]!=0)
				for(int p=k+2;p<=cnt;p++)
				{
					ans1=(ans1+bl[k]*bl[p])%mod;
					ans2=(ans2+bl[k]*bl[p]*(cnt-p))%mod;
				}
				i=cnt+1;
			}
		}
		printf("%lld %lld\n",ans1,ans2);
	}
}
/*1 0
4 3 1 1
001
010
000
000
*/