#include<bits/stdc++.h>
using namespace std;
const int N=1010;
const long long mod=998244353;
int T,d,n,m,c,f;
long long mp[N][N];
long long cc[N][N];
long long read()
{
	long long f=1,x=0;
	char q=getchar();
	while(q<'0'||q>'9')
	{
		if(q=='-') f=-1;
		q=getchar();
	}
	while(q>='0'&&q<='9')
	{
		x=x*10+q-'0';
		q=getchar();
	}
	return x*f;
}
void ba()
{
	for(int i=1,cnt;i<=n;i++)
	{
		cnt=0;
		for(int j=m;j>=1;j--)
		{
			if(mp[i][j])
			{
				mp[i][j]=-1;
				cnt=0;
			}
			else
			{
				mp[i][j]=cnt;
				cnt++;
			}
		}
	}
}
void solc()
{
	if(c==0)
	{
		cout<<0<<" ";
		return;
	}
	long long cnt,sum,ans=0;
	for(int j=1;j<m;j++)
	{
		cnt=0;
		sum=0;
		for(int i=1;i<=n;i++)
		{
			if(mp[i][j]==-1)
			{
				cnt=0;
				sum=0;
				continue;
			}
			cnt++;
			if(cnt>=3)
			{
				sum+=mp[i-2][j];
				cc[i][j]=mp[i][j]*sum%mod;
//				cout<<"find: "<<ans<<" "<<sum<<" "<<mp[i][j]<<" "<<i<<" "<<j<<endl;//
				ans=(ans+cc[i][j])%mod;
			}
		}
	}
	cout<<ans<<" ";
}
void solf()
{
	if(f==0)
	{
		cout<<0<<endl;
		return;
	}
	long long ans=0,sum;
	for(int j=1;j<m;j++)
	{
		sum=0;
		for(int i=1;i<=n;i++)
		{
			if(mp[i][j]==-1)
			{
				sum=0;
				continue;
			}
			sum=(sum+cc[i-1][j])%mod;
			ans=(ans+sum)%mod;
		}
	}
	cout<<ans<<endl;
}
void work()
{
	n=read();
	m=read();
	c=read();
	f=read();
	char rs;
	for(int i=1,j;i<=n;i++)
	{
		j=0;
		while(rs!='0'&&rs!='1')
		{
			rs=getchar();
		}
		while(rs=='0'||rs=='1')
		{
			mp[i][++j]=rs-'0';
			rs=getchar();
		}
	}
	ba();
	solc();
	solf();
}
int main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	T=read();
	d=read();
	for(int i=1;i<=T;i++)
	{
		work();
	}
	return 0;
}
//rp++
