#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
int t;
char omap[1009][1009];
int leftPreSum[1009][1009];
int working[1009];
int workingtop;
const long long mods = 998244353;
int main(){
	freopen("plant.in", "r", stdin);
	freopen("plant.out","w", stdout);
	int id;
	int n,m,c,f;
	long long cans, fans;
	string tmp;
	scanf("%d %d", &t, &id);
	char toget='\n';
	for (int teamcnt=0; teamcnt<t; teamcnt++){
		cin>>n>>m>>c>>f;
		c%=mods;
		f%=mods;
		for (int i=0;i<n;i++){
			for (int j=0;j<m;j++){
				do{
					toget=getchar();
				}while (toget!='0' && toget!='1');
				omap[i][j] = toget;
			}
			leftPreSum[i][m] = 0;
			leftPreSum[i][m+1] = 0;
			for (int j=m-1; j>=0; j--){
				if (omap[i][j] == '1') leftPreSum[i][j]=0;
				else leftPreSum[i][j] = leftPreSum[i][j+1] + 1;
			}
		}
		bool isWorking = 0;
		workingtop = 0;
		cans=0;
		fans=0;
		for (int i=0;i<m-1;i++){
			isWorking = 0;
			workingtop = 0;
			for (int j=0;j<n;j++){
				if (omap[j][i]=='1'){
					if (isWorking){
						isWorking = false;
						if (workingtop>2)
						for (int k=0;k<workingtop && k<n;k++){
							if (working[k]==1) continue;
							for (int l=k+2;l<workingtop && l<n;l++){
								if (working[l]==1) continue;
								cans+=(working[k]-1)*(working[l]-1) % mods;
								cans%=mods;
							}
						}
					}
					workingtop=0;
					continue;
				}
				isWorking = 1;
				working[workingtop] = leftPreSum[j][i];
				workingtop++;
			}
			if (isWorking && workingtop>2){
				for (int k=0;k<workingtop && k<n;k++){
					if (working[k]==1) continue;
					for (int l=k+2;l<workingtop && l<n;l++){
						if (working[l]==1) continue;
						cans+=(working[k]-1)*(working[l]-1) % mods;
						cans%=mods;
					}
				}
			}
		}
		for (int i=0;i<m-1;i++){
			workingtop = 0;
			isWorking = 0;
			for (int j=0;j<n;j++){
				if (omap[j][i]=='1'){
					if (isWorking){
						isWorking = false;
						if (workingtop>=4)
						for (int k=0;k<workingtop-3 && k<n;k++){
							if (working[k]==1) continue;
							for (int l=k+2;l<workingtop-1 && l<n;l++){
								if (working[l]==1) continue;
								fans+=((workingtop-l-1)%mods)*((working[k]-1)*(working[l]-1)%mods)%mods;
								fans%=mods;
							}
						}
						workingtop=0;
					}
					continue;
				}
				isWorking = 1;
				working[workingtop] = leftPreSum[j][i];
				workingtop++;
			}
			if (isWorking && workingtop>=4){
				for (int k=0;k<workingtop-3 && k<n;k++){
					if (working[k]==1) continue;
					for (int l=k+2;l<workingtop-1 && l<n;l++){
						if (working[l]==1) continue;
						//printf("APPENDOUS %d %d at line %d\n", k, l, i);
						fans+=((workingtop-l-1)%mods)*((working[k]-1)*(working[l]-1)%mods)%mods;
						fans%=mods;
					}
				}
			}
		}
		fans = fans * f % mods;
		cans = cans * c % mods;
		printf("%lld %lld\n", cans, fans);
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}