//I love CCF!I love IOI!
//Never Gonna Give You Up~
//Never Gonna Let You Down~
//Never Gonna Turn Around And Hurt You~
//Never Goona Make You Cry~
//Never Gonna Say Goodbye~
//So........Where is my Chinese Shurufa?
//1145141919810
//Eh,Eh,Eh,Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 5,mod =  998244353;
vector<pair<int,int > >blank_col[maxn],blank_row[maxn];
int T,id,n,m,vc,vf,cntx = 0,cnty = 0;
bool visx[maxn][maxn],visy[maxn][maxn];
char plant[maxn][maxn];
long long ans1,ans2;
inline long long read(){
	int awa = 0,qwq = 1;
	char ch = getchar();
	while(!isdigit(ch)){
		if(ch == '-') qwq = -1;
		ch = getchar();		
	}
	while(isdigit(ch)){
		awa = (awa << 1) + (awa << 3) + int(ch - 48);
		ch = getchar();
	}
	return awa * qwq;
}
void print(long long x){
	if(x < 0){
		putchar('-');
		x = -x;
	}
	if(x >= 10) print(x / 10);
	putchar('0' + x % 10);
	return ;
}
inline void prepare(){
	for(register int i = 1;i <= n;i ++){
		for(register int j = 1;j <= m;j ++){
			if(plant[i][j] == '0' and plant[i][j - 1] == '1' and visx[i][j] == false){
				for(register int k = i;k <= m + 1;k ++){
					if(plant[i][k] == '0' and visx[i][j] == false){
						cntx ++;
						visx[i][k] = true;
					}
					else if(plant[i][k] == '1'){
						blank_col[i].push_back(make_pair(j,cntx));
						cout << "plant[i][j] : " << i << " " << j << "  cntx : "<< cntx << endl;
						break;
					}			
				}
				 
				cntx = 0;
			}
			if(plant[i][j] == '0' and plant[i - 1][j] == '1' and visy[i][j] == false){
				for(register int k = i;k <= n + 1;k ++){
					if(plant[k][j] == '0' and visy[i][j] == false){
						visy[i][j] == true;
						cnty ++;
					}
					else if(plant[k][j] == '1'){
						blank_row[j].push_back(make_pair(i,cnty));
						cout << "plant[i][j] : " << i << " " << j << "  cnty : "<< cnty << endl;
						break;
					}
				}
				 
				cnty = 0;
			}
		}
	}
	return ;
}
inline void putout(int ans1,int vc,int ans2,int vf){
	if(vc == 0 and vf != 0){
		printf("0");printf(" ");print(ans2 % mod * vf % mod);
	}
	else if(vc != 0 and vf == 0){
		print((ans1 * vc) % mod);printf(" ");printf("0");
	}
	else print((ans1 * vc) % mod);printf(" ");print((ans2 * vf) % mod);
	return ;
}
inline void solve(){	
	for(register int i = 1;i <= T;i ++){
		
	}
	return ;
}
inline void clear(){
	ans1 = 0;vc = 0;ans2 = 0;vf = 0;
	return ;
}
inline void check1(){
	for(register int i = 1;i <= n;i ++){
		cout << "blank_col[" << i << "] : ";
		for(register int j = 0;j < blank_col[i].size();j ++){
			cout << blank_col[i][j].first << " " << blank_col[i][j].second << "  ";
		}
		cout << endl;
	}
	for(register int i = 1;i <= m;i ++){
		cout << "blank_row[" << i << "] : ";
		for(register int j = 0;j < blank_row[i].size();j ++){
			cout << blank_row[i][j].first << " " << blank_row[i][j].second << "  ";
		}
		cout << endl;
	}
	return ;
}
inline void check2(){
	for(register int i = 0;i <= n + 1;i ++){
		for(register int j = 0;j <= m + 1;j ++){
			cout << plant[i][j] << " ";
		}
		cout << endl;
	}
}
inline void check3(){
	cout << "visx : " << endl;
	for(register int i = 1;i <= n;i ++){
		for(register int j = 1;j <= m;j ++){
			cout << visx[i][j] << " ";
		}
		cout << endl;
	}
	cout << "visy : " << endl;
	for(register int i = 1;i <= n;i ++){
		for(register int j = 1;j <= m;j ++){
			cout << visy[i][j] << " ";
		}
		cout << endl;
	}
	exit(0);
	//return ;
}
inline void pluss(){
	for(register int i = 0;i <= m + 1;i ++){
		plant[0][i] = '1';
		plant[n + 1][i] = '1';
	}
	for(register int i = 0;i <= n + 1;i ++){
		plant[i][0] = '1';
		plant[i][m + 1] = '1';
	}
	return ;
}
inline void init(){
	T = read();id = read();
	for(register int t = 1;t <= T;t ++){
		n = read();m = read();vc = read();vf = read();
		if(vc == 0 and vf == 0){
			printf("0 0");
			continue ;
		}
		for(register int i = 1;i <= n;i ++){
			for(register int j = 1;j <= m;j ++){
				plant[i][j] = getchar();
			}
			getchar();
		}
		pluss();
		check2();
		prepare();
		check1();
		check3();
		solve();
		putout(ans1,vc,ans2,vf);
		clear();
	}
	
	return ;
}

int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	
	//freopen("plant.in","w",stdin);
	//freopen("plant.out","r",stdout);
	//freopen("plant.in","w",stdout);
	//freopen("plant.out","r",stdin);
	//hhhhhhhhhhhhhh
	//1145141919810
	//Eh,Eh,Eh,Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa	
	init();
	fclose(stdin);fclose(stdout);
	return 0;
}
//Bilibili:CountTheSky
//Bilibili and Luogu:ElonaSerikas
//I love CCF!I love NOI!
//So,could you give me more price?
//Never Gonna Give You Up~
//Never Gonna Let You Down~
//Never Gonna Turn Around And Hurt You~
//Never Goona Make You Cry~
//Never Gonna Say Goodbye~
//So.......I couldn't find my Chinese Shurufa..........
//Really!!!
//1145141919810
//Eh,Eh,Eh,Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
