#include<bits/stdc++.h>
#define endl '\n'
#define fir first
#define sec second
#define ri register
#define pb push_back
#define mp make_pair
#define int long long
#define inf 2147483647
#define Swap(x,y) ((x)^=(y)^=(x)^=(y))
#define reset(x,y) memset((x),(y),sizeof((x)))
#define fastcin ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
/* May all the beauty be blessed. */
using namespace std;
inline int read()
{
	ri int x=0,f=0;ri char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') f=1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c-'0'),c=getchar();
	return f?-x:x;
}
inline void write(int x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10+'0');
}
const int N=1e3+10,mod=998244353;
int T,id,n,m,c,f,ans1,ans2,a[N][N],s[N][N],x[N][N],y[N][N];
char ch;
signed main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	fastcin,cin>>T>>id;while(T--)
	{
		cin>>n>>m>>c>>f,ans1=ans2=0;
		for(ri int i=1;i<=n;++i)
			for(ri int j=1;j<=m;++j)
				a[i][j]=s[i][j]=x[i][j]=y[i][j]=0;
		for(ri int i=1;i<=n;++i)
		{
			for(ri int j=1;j<=m;++j)
				cin>>ch,s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+(a[i][j]=ch-'0');
			for(ri int j=m;j;--j)
				x[i][j]=(a[i][j]?0:x[i][j+1]+1);
		}
		for(ri int j=1;j<=m;++j)
			for(ri int i=n;i;--i)
				y[i][j]=(a[i][j]?0:y[i+1][j]+1);
		for(ri int i=1;i<=n;++i)
			for(ri int k=1;k<=m;++k)
				if(y[i][k]>=3) for(ri int j=i+2;j<=i+y[i][k]-1;++j)
					ans1=(ans1+(x[i][k]-1)*(x[j][k]-1)%mod)%mod,
					ans2=(ans2+(x[i][k]-1)*(x[j][k]-1)%mod*(y[j][k]-1)%mod)%mod;
		cout<<ans1*c%mod<<" "<<ans2*f%mod<<endl;
	}
	return 0;
}
//O(n^2*m*T) 72pts
