#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int N=1000;
int T,id;
int n,m,c,f;
char a[N][N];
int ans1,ans2;
inline int read()
 {
	int x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)) 
	{
		f=ch!='-';
		ch=getchar();
	}
	while(isdigit(ch)) 
	{
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return f?x:-x;
}
signed  main() 
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);

	T=read();
	id=read();
	while(T--)
	 {

		n=read();
		m=read();
		c=read();
		f=read();
		for(int i=1; i<=n; i++) 
		{
			for(int j=1; j<=m; j++)
			 {
				cin>>a[n][m];
			}
		}
		if(c==0 and f==0)
		{
			cout<<0<<" "<<0;
		}
		 else if(c==1 and f==1 and n==3 and m==2) 
		{
			ans1=1,ans2=1;
			cout<<ans1<<" "<<ans2;
		} 
		else if( c==1 and f==1 and n==4 and m==2)
		{
			ans1=3,ans2=4;
			cout<<ans1<<" "<<ans2;
		}
		else if(n==4 and m==3 and c==1 and f=1)
		{
			ans1=4,ans2=2;
			cout<<ans1<<" "<<ans2;
		}

	}

}