#include<bits/stdc++.h> 
using namespace std;
const int maxx=1005;
const int mod=998244353;
char tu[maxx][maxx];
bool g[maxx][maxx];
int n,m,c,f;
int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	ios::sync_with_stdio(false);
	memset(g,0x3f,sizeof(g));
	int t,id;
	cin>>t>>id;
	while(t>0){
	t--;
   	int ans1=0;
   	cin>>n>>m>>c>>f;
   	for(int i=1;i<=n;i++){
   		for(int j=1;j<=m;j++){
   			cin>>tu[i][j];
   			if(tu[i][j]=='0') g[i][j]=0;
   			else g[i][j]=1;
		}
	}
	for(int i=1;i<=n-2;i++){
		for(int j=1;j<=m-1;j++)
			if(g[i][j]==0&&g[i+1][j]==0&&g[i+2][j]==0){
				for(int k=i+2;k<=n;k++){
					int len1=j;
					int len2=j;
					while(g[i][++len1]==0&&len1+1<=m){
						len1++;
					}
					while(g[k][++len2]==0&&len2+1<=m){
						len2++;
					}
					ans1=ans1+(len1-j)*(len2-j);
				}
			}
	}
	ans1=(ans1*c)%mod;
	cout<<ans1<<endl;
}
	return 0;
	fclose(stdin);
	fclose(stdout);
}
