#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mo=998244353;
const int N=1005;
int c,f,n,m;
int a[N][N],Right[N][N];
int down[N][N];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int T,id;
 	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
 
    cin>>T>>id;
    while(T--)
    {
    	ll ansc=0,ansf=0;
    	cin>>n>>m>>c>>f;
//    	swap(n,m);
//    	cout<<m;
    	char input_c;
    	for(int i=1;i<=n;++i)
    	{
    		for(int j=1;j<=m;++j)
    		{
    			input_c=cin.get();
    			while(input_c!='0'&&input_c!='1')
    			{
    				input_c=cin.get();
				}
				Right[i][j]=0;
				Right[i][j+1]=0;
				Right[i+1][j]=0;
				down[i][j]=0;
				down[i][j+1]=0;
				down[i+1][j]=0;
				a[i][j]=input_c-'0';
			
			}
		}
		for(int i=n;i>0;--i)
		{
			for(int j=m;j>0;--j)
			{
 
				if(a[i][j]==0)
				{
					Right[i][j]=Right[i][j+1]+1;
					down[i][j]=down[i+1][j]+1;
//					cout<<i<<" "<<j<<"i j is"<<" "<<a[i][j]<<" "<<down[i][j]<<" "<<Right[i][j]<<"\n";
				}
//				cout<<m<<"edcwdw";
			}
		
		}
		for(int i=1;i<=n;++i)
		{
			for(int j=1;j<=m;++j)
			{
				if(a[i][j]==1||a[i+1][j]==1) continue;
				for(int k=i+2;k<=n;++k)
				{
					if(a[k][j]==1) break;
					else
					{
						ansc=(ansc+max(0,(Right[i][j]-1)*(Right[k][j]-1)))%mo;
						ansf=(ansf+max(0ll,(Right[i][j]-1)*(Right[k][j]-1)*(ll)(down[k][j]-1)))%mo;
//						cout<<i<<" "<<j<<" "<<k<<" "<<max(0,(Right[i][j]-1)*(Right[k][j]-1))<<" "<<max(0ll,(Right[i][j]-1)*(Right[k][j]-1)*(ll)(down[k][j]-1))<<"\n";
					}
				}
			}
		}
//		cout<<a[2][1]<<"}}}";
		cout<<c*ansc%mo<<" "<<f*ansf%mo<<"\n";
	}
}
