// Fresh Peach Heart Shower
#include <bits/stdc++.h>
#define pb push_back
#define MP std::make_pair
#define ALL(x) (x).begin(),(x).end()
#define mem(x,y) memset(x,y,sizeof(x))
#ifdef _LOCAL_
#define dprintf(x...) fprintf(stderr,x)
#else
#define dprintf(x...) 42
#endif
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,b,a) for(int i=(b);i>=(a);--i)
typedef std::vector<int > poly;
typedef std::pair<int,int > pii;
void setIn(std::string s){freopen(s.c_str(),"r",stdin);}
void setOut(std::string s){freopen(s.c_str(),"w",stdout);}
void setIO(std::string s){setIn(s+".in"),setOut(s+".out");}
template <class t> inline bool ckmin(t&x,t y){if(x>y)return x=y,1;return 0;}
template <class t> inline bool ckmax(t&x,t y){if(x<y)return x=y,1;return 0;}
inline int lowbit(int x){return x&(-x);}
const int MaxN=1050;
const int p=998244353;
struct mint
{
	int v;
	mint(){v=0;}
	bool check(long long x){return 0<=x&&x<p;}
	mint(int x)
	{
		if(check(x))v=x;
		else v=(x%p+p)%p;
	}
	mint(long long x)
	{
		if(check(x))v=x;
		else v=(x%p+p)%p;
	}
	mint operator + (const mint &nt) const
	{
		return mint(v>=p-nt.v?v-p+nt.v:v+nt.v);
	}
	mint operator - (const mint &nt) const
	{
		return mint(v>=nt.v?v-nt.v:v-nt.v+p);
	}
	mint operator * (const mint &nt) const
	{
		return mint(1LL*v*nt.v%p);
	}
	int fpow(int a,long long b) const
	{
		int ret=1;
		for(;b;b>>=1,a=1LL*a*a%p)if(b&1)ret=1LL*ret*a%p;
		return ret;
	}
	mint pow(long long b) const{return mint(fpow(v,b));}
	mint inv() const{return mint(fpow(v,p-2));}
	mint operator / (const mint &nt) const{return nt.inv()*v;}
	mint operator += (const mint &nt){return *this=*this+nt;}
	mint operator -= (const mint &nt){return *this=*this-nt;}
	mint operator *= (const mint &nt){return *this=*this*nt;}
	mint operator /= (const mint &nt){return *this=*this/nt;}
};
char a[MaxN][MaxN];
int R[MaxN][MaxN];
void work()
{
	int n,m,C,F;std::cin>>n>>m>>C>>F;
	rep(i,1,n)std::cin>>(a[i]+1);
	rep(i,0,n+1)rep(j,0,m+1)R[i][j]=j;
	rep(i,1,n)
	{
		per(j,m,1)
		{
			if(a[i][j]=='0')
				R[i][j]=R[i][j+1];
			else R[i][j]=j;
		}
	}
	mint ansc=0,ansf=0;
	rep(j,1,m)
	{
		mint cnt=0;
		int pos=1;
		rep(i,1,n)
		{
			if(R[i][j]==j)
			{
				cnt=0;
				pos=i+1;
				continue;
			}
			while(pos+1<i)
			{
				if(R[pos][j]-j>=2)cnt+=R[pos][j]-j-1;
				++pos;
			}
			if(R[i][j]-j>=2)ansc+=cnt*(R[i][j]-j-1);
		}
	}

	rep(j,1,m)
	{
		mint s1=0,s2=0;
		int pos=1;
		rep(i,1,n)
		{
			if(R[i][j]==j)
			{
				s1=0,s2=0;
				pos=i+1;
				continue;
			}
			ansf+=s2;
			while(pos+1<i)
			{
				if(R[pos][j]-j>=2)s1+=R[pos][j]-j-1;
				++pos;
			}
			if(R[i][j]-j>=2)s2+=s1*(R[i][j]-j-1);
		}
	}

	std::cout<<(ansc*C).v<<' '<<(ansf*F).v<<'\n';
}
signed main(void)
{
#ifndef _LOCAL_
	std::ios::sync_with_stdio(false),std::cin.tie(0);
#endif
	
	setIO("plant");

	int t,Id;
	std::cin>>t>>Id;
	while(t--)work();
	return 0;
}


