#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e3+5,P=998244353;
int T,idx;
char a[N][N];
bool checkyy(int x1,int x2,int y0)
{
	for(int i=x1;i<=x2;i++)
		if(a[i][y0]=='1') return false;
	return true;
}
bool checkxx(int x0,int y0,int y1)
{
	for(int i=y0;i<=y1;i++)
		if(a[x0][i]=='1') return false;
	return true;
}
int main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	scanf("%d%d",&T,&idx);//yxc's bless!!!
	while(T--)
	{
		LL vc=0,vf=0;
		int n,m,c,f;
		scanf("%d%d%d%d",&n,&m,&c,&f);
		for(int i=0;i<n;i++) scanf("%s",a[i]);
		if(c==0&&f==0) {printf("0 0\n");continue;}
		else
		{
			for(int x1=0;x1<n;x1++)
			{
				for(int x2=x1+2;x2<n;x2++) //run through x1 and x2
				{
					for(int y0=0;y0<m;y0++)
					{
						LL nowvc=0;
						if(!checkyy(x1,x2,y0)) continue;
						for(int y1=y0+1;y1<m;y1++)
						{
							if(!checkxx(x1,y0,y1)) break;
							for(int y2=y0+1;y2<m;y2++)
							{
								if(!checkxx(x2,y0,y2)) break;
								vc++;nowvc++;
								//cout<<x1+1<<x2+1<<y0+1<<y1+1<<y2+1<<endl;
								//Line48 is my way of debugging...
								//The test is pass.But don't let me FST;rp++;yxc++;
							}
						}
						if(f&&nowvc&&x2+1<n)
						{
							for(int x3=x2+1;x3<n;x3++)
								if(a[x3][y0]!='1') vf+=nowvc;
								else break;
						}	
					}
				}
			}
			printf("%d %d\n",c*vc%P,f*vf%P);	
		}
	}
	return 0;
}
