#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0)
#define lowbit(x) (x&(-x))
#define int long long
using namespace std;
const int N=1e3+10,mod=998244353;
string st;
int n,m,C,F,a[N][N],h1[N][N],h2[N][N],w1[N][N],w2[N][N],ans,pre[N];;
void solve()
{
	cin>>n>>m>>C>>F;
	for (int i=1;i<=n;i++)
	{
		cin>>st; st=' '+st;
		for (int j=1;j<=m;j++) a[i][j]=st[j]-'0',h1[i][j]=h2[i][j]=w1[i][j]=w2[i][j]=0;
	}
	for (int j=1;j<=m;j++)
		for (int i=1;i<=n;i++) h1[i][j]=h1[i-1][j]+(a[i][j]==0);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++) h2[i][j]=h2[i][j-1]+(a[i][j]==0);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
		{
			int l=j,r=m,res=l;
			while (l<=r)
			{
				int mid=(l+r)>>1;
				if (h2[i][mid]-h2[i][j-1]==mid-j+1) res=mid,l=mid+1; else r=mid-1;
			}
			w1[i][j]=res-j;
			l=i; r=n; res=l;
			while (l<=r)
			{
				int mid=(l+r)>>1;
				if (h1[mid][j]-h1[i-1][j]==mid-i+1) res=mid,l=mid+1; else r=mid-1;
			}
			w2[i][j]=res-i;
		}
	for (int j=1;j<=m;j++)
	{
		for (int i=1;i<=n;i++)
		{
			pre[i]=(pre[i-1]+w1[i][j])%mod;
			if (a[i][j]==1) pre[i]=pre[i-1]=0;
			ans=(ans+pre[i-2]*w1[i][j]%mod)%mod;
		}
	}
	cout<<ans<<' '; ans=0;
	for (int j=1;j<=m;j++)
	{
		for (int i=1;i<=n;i++)
		{
			pre[i]=(pre[i-1]+w1[i][j])%mod;
			if (a[i][j]==1) pre[i]=pre[i-1]=0;
			ans=(ans+pre[i-2]*w1[i][j]%mod*w2[i][j])%mod;
		}
	}
	cout<<ans<<'\n'; ans=0;
}
signed main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	IOS; int T,ID; cin>>T>>ID;
	while (T--) solve();
}
