#include<bits/stdc++.h>
using namespace std;
int a[1001][1001];
int n,m,c,f;
long long ans,cnt;
void find(int x,int y)
{
	for(int i=y-1;i>=1;i--)
	{
		if(a[x][i]==0&&a[x+1][i]==0&&a[x+2][i]==0)
		{		
			for(int j=2;j+x<=n;j++)
			{
				if(a[x+j][i]==0)
				{
					int cntl=0;
					for(int u=x+j+1;u<=n;u++)
					{
						if(a[u][i]==0)
							cntl++;
						else
							break;
					}
					int now=i+1;
					while(a[x+j][now]==0&&now<=m)
					{
						ans=(ans+1)%998244353;
						now++;
						cnt=(cntl+cnt)%998244353;
					}		
				}
				else
					break;
			}
		}
		else
		if(a[x][i]!=0)
			break;
	}
}
int main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	for(int i=1;i<=t;i++)
	{
		ans=0;
		cnt=0;
		int id;
		cin>>id;
		cin>>n>>m>>c>>f;
		string p;
		int h=1;
		for(int j=1;j<=n;j++)
		{
			cin>>p;
			for(int o=0;o<m;o++)
				a[h][o+1]=int(p[o])-48;
			h++;		
		}
		for(int j=1;j<=n-2;j++)
		{
			for(int q=2;q<=m;q++)
			{
				if(a[j][q]==0)
					find(j,q);
			}				
		}
		if(c!=0)
			cout<<ans;
		else
			cout<<c;
		cout<<" ";
		if(f!=0)
			cout<<cnt;
		else
			cout<<f;						
	}	
	return 0;
}