#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define up(i,x,y) for(int i=x,i##E=y;i<=i##E;i++)
#define pu(i,x,y) for(int i=x,i##E=y;i>=i##E;i--)
#define up_(x) up(i,1,x)
#define mc cerr<<"qwq\n"
#define edl puts("")
#define pii pair<int,int>
#define mkp make_pair
#define ep push_back
#define vi vector<int>
#define upn up(i,1,n)
#define upm up(j,1,m)
const int mod=998244353;
int n,m,c,f;
char ch[1010];
bool b[1010][1010];
int r[1010][1010];
int d[1010][1010];
signed main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	int T,id;scanf("%lld%lld",&T,&id);
	while(T--)
	{
		scanf("%lld%lld%lld%lld",&n,&m,&c,&f);
		up_(n)
		{
			scanf("%s",ch+1);
			up(j,1,m)b[i][j]=ch[j]-'0';
		}
		up_(n)
		{
			r[i][m+1]=-1;
			pu(j,m,1)
			{
				if(b[i][j]==1)r[i][j]=-1;
				else
				{
					r[i][j]=r[i][j+1]+1;
				}
			}
		}
		up(j,1,m)
		{
			d[n+1][j]=-1;
			pu(i,n,1)
			{
				if(b[i][j]==0)d[i][j]=d[i+1][j]+1;
				else d[i][j]=-1;
			}
		}
		int ansc=0,ansf=0;
		up(j,1,m)
		{
			int nw=0,las=0;
			up(i,1,n)
			{
				if(b[i][j]==1)
				{
					nw=las=0;continue;
				}
				ansc+=r[i][j]*(nw-las)%mod;
				ansc%=mod;
				ansf+=r[i][j]*(nw-las)%mod*d[i][j]%mod;
				ansf%=mod;
				nw+=r[i][j];las=r[i][j];
			}
		}
		cout<<ansc*c<<" "<<ansf*f;edl;
	}
	
	
	return 0;
}