#include <bits/stdc++.h> 
#define fp( i , x , y ) for( int i=(x); i<=(y); ++i ) 
#define fq( i , x , y ) for( int i=(y); i>=(x); --i ) 
using namespace std ; 
const int N = 1005 , mod = 998244353 ;  
int a[N][N] , n , m , C , F , D[N][N] , R[N][N] ; 
void upd( int &x , int y ) { x += y ; if( x >= mod ) x -= mod ; } 
void solve( ) { 
  memset( R , 0 , sizeof(R) ) ; 
  memset( D , 0 , sizeof(D) ) ; 
  cin >> n >> m >> C >> F ; 
  string s ; 
  fp( i , 1 , n ) { 
    cin >> s ; 
    fp( j , 1 , m ) a[i][j] = (s[j-1] == '1') ; 
  } 
  fp( i , 1 , n ) fq( j , 1 , m ) { 
    R[i][j] = R[i][j+1] + 1 ;  
    if( a[i][j] == 1 ) R[i][j] = 0 ; 
  } 
  fp( j , 1 , m ) fq( i , 1 , n ) { 
    D[i][j] = D[i+1][j] + 1 ;  
    if( a[i][j] == 1 ) D[i][j] = 0 ;  
  } 
  int ans , ansc = 0 , ansf = 0 , t ; 
  fp( j , 1 , m ) { 
    t = 0 ; 
    fp( i , 1 , n ) { 
      if( i-2 > 0 ) { 
        upd( t , R[i-2][j] - 1 ) ; 
        if( a[i-2][j] ) t = 0 ; 
	  } 
	  if( a[i-1][j] || a[i][j] ) t = 0 ; 
	  if( t ) 
	   upd( ansf , 1ll * t * (R[i][j]-1) * (D[i][j]-1) % mod ) , 
	   upd( ansc , 1ll * t * (R[i][j]-1) % mod ) ;  
	} 
  }  
  cout << ansc * C << ' ' << ansf * F << '\n' ; 
} 
signed main( ) { 
  freopen( "plant.in" , "r" , stdin ) ; 
  freopen( "plant.out" , "w" , stdout ) ; 
  ios::sync_with_stdio(false) ; 
  cin.tie(0) ; 
  int T , id ; 
  cin >> T >> id ; 
  while( T -- ) solve() ;  
  return 0 ; 
} 
