#include<bits/stdc++.h>
using namespace std;
long long a[2000][2000],T,idbianhao,n,m,c,f,ansc,ansf,vc=998244353,vf=998244353;
char aa[2000];
int main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	cin>>T>>idbianhao;
	for(long long q=1;q<=T;q++)
	{
		cin>>n>>m>>c>>f;
		ansc=0;
		ansf=0;
		memset(a,0,sizeof(a));
		for(long long i=1;i<=n;i++)
		   for(long long j=1;j<=m;j++)
		   {
		   	    cin>>aa[j];
		   	    if(aa[j]=='0')a[i][j]=0;
		   	    else a[i][j]=1;
		   }
		
		if(c==0){
			cout<<"0 0"<<endl;
		}
		else if(c!=0){
			for(long long i=1;i<=n-2;i++)
			{
				for(long long j=1;j<=m-1;j++)
				{
				    long long ddj=j,c1=1;long long ansc1=0,ansf1=0,anscc=0;
					if(a[i][j]==0 and a[i][j+1]==0 and a[i+1][j]==0 and a[i+2][j]==0)
					{
						while(a[i][ddj+1]==0 and ddj<m){ddj++;}
						c1=c*(ddj-j);
						for(long long p=i+2;p<=n;p++)
						{
							if(a[p][j]==0 and a[p][j+1]==0){
								ddj=j;
					        	while(a[p][ddj+1]==0 and ddj<m){ddj++;}
					        	ansc1+=(ddj-j);
					        	anscc=ddj-j;
					        	//cout<<p<<" "<<j<<" "<<ddj<<" "<<j<<endl;
					        	//cout<<p<<" "<<j<<" "<<ansc1<<endl;
					        	if(f!=0){
					        		long long nowf=p,ansf1=1;
					        		if(nowf<=n){
					        			while(nowf<n and a[nowf+1][j]==0){nowf++;}
					        			if(nowf>p)ansf1=(nowf-p)%vf;
					        			else ansf1=0;
					        			//cout<<"!"<<p<<" "<<j<<" "<<nowf<<" "<<p<<" "<<ansf1<<endl;
					        				ansf+=c1*anscc*ansf1%vf;
							            //cout<<i<<" "<<p<<" "<<j<<" "<<c1<<" "<<anscc<<" "<<ansc<<" "<<ansf1<<" "<<ansf<<endl;
									}
					        		
								}
							}
						
						}
						
					}
					ansc+=c1*ansc1%vc;
					//cout<<"%%"<<i<<" "<<j<<" "<<c1<<" "<<ansc1<<" "<<ansc<<" "<<ansf1<<" "<<ansf<<endl;
					
				}
			}
		cout<<ansc<<" "<<ansf<<endl;
		}
		
	}
	return 0;
}
