#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MAXN 1010
#define MOD 998244353
int T,id,n,m,c,f;
int mapp[MAXN][MAXN],st[MAXN][MAXN],en[MAXN][MAXN];
int last_num[MAXN],last_link[MAXN],now_link[MAXN];
ll tot[MAXN],len[MAXN];
ll solve(int x,int f,int t,char m)
{
	if(t-f+1<3)
	{
		return 0;
	}
	//cout<<"solve:"<<x<<' '<<f<<' '<<t<<endl;
	for(int i=f;i<=t;++i)
	{
		while(x>en[i][now_link[i]]||now_link[i]>last_link[i])
		{
			++now_link[i];
			//cout<<"now_link "<<i<<" = "<<now_link[i]<<endl;
		}
		if(now_link[i]<=last_link[i]&&x>=st[i][now_link[i]])
		{
			len[i]=max(en[i][now_link[i]]-x,0);
			//cout<<"len "<<i<<" = "<<len[i]<<endl;
		}
		else
		{
			len[i]=0;
			//cout<<"len "<<i<<" = "<<len[i]<<endl;
		}
	}
	tot[t]=len[t];
	//cout<<"tot "<<t<<" = "<<tot[t]<<endl;
	if(m=='C')
	{
		for(int i=t-1;i>=f;--i)
		{
			tot[i]=(tot[i+1]+len[i])%MOD;
			//cout<<"tot "<<i<<" = "<<tot[i]<<endl;
		}
	}
	else
	{
		for(int i=t-1;i>=f;--i)
		{
			tot[i]=(tot[i+1]+len[i]*(t-i+1))%MOD;
			//cout<<"tot "<<i<<" = "<<tot[i]<<endl;
		}
	}
	int now_ans=0;
	for(int i=f;i<=t-2;++i)
	{
		now_ans=(now_ans+len[i]*tot[i+2])%MOD;
		//cout<<i<<' '<<len[i]<<' '<<i+2<<' '<<tot[i+2]<<endl;
		//cout<<"now_ans = "<<now_ans<<endl;
	}
	//cout<<"now_ans = "<<now_ans<<endl;
	return now_ans;
}
void CF_solve()
{
	int fr,t;
	ll C_ans=0,F_ans=0;
	for(int i=1;i<=m;++i)
	{
		fr=0,t=-1;
		for(int j=1;j<=n;++j)
		{
			if(mapp[j][i]==0)
			{
				if(j!=t+1)
				{
					//cout<<"CFsolve:"<<i<<' '<<fr<<' '<<t<<endl;
					if(f) F_ans=(F_ans+solve(i,fr,t-1,'F'))%MOD;
					if(c) C_ans=(C_ans+solve(i,fr,t,'C'))%MOD;
					//cout<<"?????????????"<<F_ans<<endl;
					fr=j;
				}
				t=j;
			}
		}
		//cout<<"CFsolve:"<<i<<' '<<fr<<' '<<t<<endl;
		if(f) F_ans=(F_ans+solve(i,fr,t-1,'F'))%MOD;
		if(c) C_ans=(C_ans+solve(i,fr,t,'C'))%MOD;
		//cout<<"?????????????"<<F_ans<<endl;
	}
	//cout<<")))))))))))))))"<<c<<' '<<f<<endl;
	if(c)
	{
		cout<<C_ans<<' ';
	}
	else
	{
		cout<<"0 ";
	}
	if(f)
	{
		cout<<F_ans<<endl;
	}
	else
	{
		cout<<"0"<<endl;
	}
}
int main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>T>>id;
	for(int a=1,x;a<=T;++a)
	{
		cin>>n>>m>>c>>f;
		//cout<<")))))))))))))))"<<c<<' '<<f<<endl;
		for(int i=1;i<=n;++i)
		{
			last_num[i]=-1;
			last_link[i]=0;
			now_link[i]=0;
		}
		for(int i=1;i<=n;++i)
		{
			string in;
			cin>>in;
			for(int j=1;j<=m;++j)
			{
				x=in[j-1]-'0';
				mapp[i][j]=x;
				if(x==0)
				{
					if(j!=last_num[i]+1)
					{
						en[i][last_link[i]]=last_num[i];
						++last_link[i];
						st[i][last_link[i]]=j;
					}
					last_num[i]=j;
				}
			}
			en[i][last_link[i]]=last_num[i];
		}
		/*for(int i=1;i<=n;++i)
		{
			for(int j=1;j<=m;++j)
			{
				cout<<mapp[i][j]<<' ';
			}
			cout<<endl;
		}*/
		/*for(int i=0;i<=n;++i)
		{
			for(int j=0;j<=last_link[i];++j)
			{
				cout<<i<<' '<<j<<"  :"<<st[i][j]<<' '<<en[i][j]<<endl;
			}
		}*/
		if(c==0&&f==0)
		{
			cout<<"0 0"<<endl;
		}
		else
		{
			CF_solve();
		}
	}
}
/*
1 0
4 3 1 1
001
010
000
000
*/
