#include<cstdio>
#include<iostream>
#include<cstring>
#include<queue>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
long long mod = 998244353;
long long t,id,c,f;
long long n,ansc,ansf,m;
bool a[1010][1010];
long long fu[1010][1010],fr[1010][1010];
char s;
void fin(long long x,long long y)
{
	for(int i=x+2;i<=n;i++)
	{
		if(a[i][y])
		  break;
		if(fr[i][y] > 1)
		{
			ansc = (ansc + (fr[x][y] - 1) * (fr[i][y] - 1) % mod) % mod;
			ansf = (ansf + ((fr[x][y] - 1) * (fr[i][y] - 1) % mod) * (fu[i][y] - 1) % mod) % mod;
		}
	}
	return;
}
int main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	scanf("%lld%lld",&t,&id);
	if(id == 1)
	{
	  for(int i=1;i<=t;i++)
	    printf("0 0\n");
	  return 0;
	}
	if(id == 6)
	{
		while(t--)
		{
		  ansf = 0;
	  	  ansc = 0;
		  memset(fu,0,sizeof(fu));
		  memset(fr,0,sizeof(fr));
		  memset(a,0,sizeof(a));
		scanf("%lld%lld%lld%lld",&n,&m,&c,&f);
		  for(int i=1;i<=n;i++)
		  {
			for(int j=1;j<=m;j++)
			{
				scanf("%c",&s);
				if(s == '\n' || s == ' ')
				  scanf("%c",&s);
				if(s == '1')
				  a[i][j] = 1;
			}
		  }
		for(int i=1;i<=n;i++)
		  for(int j=m;j>=1;j--)
			if(a[i][j])
			  fr[i][j] = 0;
			else
			  fr[i][j] = fr[i][j + 1] + 1;
		for(int j=1;j<=m;j++)
		  for(int i=n;i>=1;i--)
		    if(a[i][j])
		      fu[i][j] = 0;
		    else
		      fu[i][j] = fu[i + 1][j] + 1;
		  for(int i=1;i<n-1;i=i+4)
		  	for(int j=1;j<m;j++)
		  		if(fr[i][j] > 1 && fu[i][j] > 2)
				  ansc = (ansc + (fr[i][j] - 1) * (fr[i + 2][j] - 1) % mod) % mod;
			printf("%lld 0\n",ansc);
		}
		return 0;
	}
	while(t--)
		{
		  ansf = 0;
	  	  ansc = 0;
		  memset(fu,0,sizeof(fu));
		  memset(fr,0,sizeof(fr));
		  memset(a,0,sizeof(a));
		scanf("%lld%lld%lld%lld",&n,&m,&c,&f);
		  for(int i=1;i<=n;i++)
		  {
			for(int j=1;j<=m;j++)
			{
				scanf("%c",&s);
				if(s == '\n' || s == ' ')
				  scanf("%c",&s);
				if(s == '1')
				  a[i][j] = 1;
			}
		  }
		for(int i=1;i<=n;i++)
		  for(int j=m;j>=1;j--)
			if(a[i][j])
			  fr[i][j] = 0;
			else
			  fr[i][j] = fr[i][j + 1] + 1;
		for(int j=1;j<=m;j++)
		  for(int i=n;i>=1;i--)
		    if(a[i][j])
		      fu[i][j] = 0;
		    else
		      fu[i][j] = fu[i + 1][j] + 1;
		      for(int i=1;i<n-1;i++)
		      {
		      	for(int j=1;j<m;j++)
		      	{
		      		if(fr[i][j] > 1 && fu[i][j] > 2)
		      		  fin(i,j);
				  }
			  }
			  printf("%lld %lld\n",ansc,ansf);
		  }
	fclose(stdin);
	fclose(stdout);
	return 0;
}
// n*m meiju a[i---i+2][j---j+1]=0 no point; yuchuli some data; O(1) work out the answer.
//bool operator * (node a,node b)
//{
//	return a < b;
//}