#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int n,m,t,id;
char a[1010][1010];
long long ansf,ansc,f[1010][1010],js,jc,qc,qf,Mod=998244353,js1;
 int main()
 {
 	 freopen("plant.in","r",stdin);
 	 freopen("plant.out","w",stdout);
 	scanf("%d%d",&t,&id);
   while (t--)
   {
   	   memset(f,0,sizeof(f));
   	   ansf=0;
   	   ansc=0;
 	   scanf("%d%d%lld%lld",&n,&m,&qc,&qf);
 	   for (int i=1;i<=n;i++)
         for (int j=1;j<=m;j++)
 	   	   cin>>a[i][j];
	   for(int i=1;i<=n;i++)
	     for (int j=m;j>=1;j--)
	      if (a[i][j]=='0')
	       f[i][j]=f[i][j+1]+1;
	    for (int i=1;i<=m;i++)
	    {
	      js=0;
	      jc=0;
	      js1=0;
	     for (int j=1;j<=n;j++)
	       if (f[j][i])
	       {
	       	   ansf=(ansf+js1)%Mod;
	       	   ansc=(ansc+js*(f[j][i]-1)%Mod)%Mod;
	       	   js1=(js1+js*(f[j][i]-1)%Mod)%Mod;
	       	   js=js+jc;
	       	   jc=f[j][i]-1;
		   }
		  else
		  js=0,jc=0,js1=0;
	    }
		printf("%lld %lld\n",ansc*qc%Mod,ansf*qf%Mod);
	}
 	 fclose(stdin);
 	 fclose(stdout);
 	 return 0;
 }