#include <bits/stdc++.h>
using namespace std;

const int S=1000+5;

char g[S][S];
int n,m,d;
int ok1[S][S],ok2[S][S],used1[S][S],used2[S][S],Ti,T1,T2;

inline void dfs(int nx,int ny,int rem,int vis[S][S],int tag)
{
	vis[nx][ny]=tag;
	if (!rem) return;
	if (nx>1 && g[nx-1][ny]!='X' && vis[nx-1][ny]!=tag) dfs(nx-1,ny,rem-1,vis,tag);
	if (nx<n && g[nx+1][ny]!='X' && vis[nx+1][ny]!=tag) dfs(nx+1,ny,rem-1,vis,tag);
	if (ny>1 && g[nx][ny-1]!='X' && vis[nx][ny-1]!=tag) dfs(nx,ny-1,rem-1,vis,tag);
	if (ny<m && g[nx][ny+1]!='X' && vis[nx][ny+1]!=tag) dfs(nx,ny+1,rem-1,vis,tag);
}

inline void over(int x,int y)
{
	for (int i=1;i<=n;++i)
		for (int j=1;j<=m;++j)
			if (g[i][j]!='X' && !(i==x && j==y))
			{
				printf("%d %d %d %d\n",x,y,i,j);
				exit(0);
			}
	printf("-1\n");
	exit(0);
}

inline void over(int x1,int y1,int x2,int y2)
{
	printf("%d %d %d %d\n",x1,y1,x2,y2);
	exit(0);
}

int main(int argc,char **argv)
{
	int sx,sy,nx,ny;
	scanf("%d%d%d",&n,&m,&d);
	for (int i=1;i<=n;++i)
		for (int j=1;j<=m;++j)
		{
			scanf(" %c",&g[i][j]);
			if (g[i][j]=='R') sx=i,sy=j;
		}
	dfs(sx,sy,d,ok1,1);
	for (int i=1;i<=n;++i)
		for (int j=1;j<=m;++j)
			if (ok1[i][j] && g[i][j]!='X')
			{
				dfs(i,j,d,used1,++T1);
				for (nx=1;nx<=n;++nx)
					for (ny=1;ny<=m;++ny)
						if (g[nx][ny]=='R' && used1[nx][ny]!=T1)
							goto FIND;
				over(i,j);
				FIND:;
				dfs(nx,ny,d,ok2,++Ti);
				for (int k=1;k<=n;++k)
					for (int l=1;l<=m;++l)
						if (ok2[k][l]==Ti && g[k][l]!='X')
						{
							dfs(k,l,d,used2,++T2);
							for (nx=1;nx<=n;++nx)
								for (ny=1;ny<=m;++ny)
									if (g[nx][ny]=='R' && used1[nx][ny]!=T1 && used2[nx][ny]!=T2)
										goto FAIL;
							over(i,j,k,l);
							FAIL:;
						}
			}
	printf("-1\n");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1005;
const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
struct node{int x,y,now;}rats[N*N];
int n,m,d,cnt,sum,ans1,ans2,num[N][N],x[N],y[N],a[N][N];
char s[N][N];
int vis[N][N],mark[N][N];
void get(int xx,int yy,int step)
{
	if (!num[xx][yy])
	 {
		vis[++sum][step]=1;
		x[sum]=xx,y[sum]=yy;
		num[xx][yy]=1;
		return;
	 }
	for (int i=1;i<=sum;i++)
	 if (x[i]==xx&&y[i]==yy)
	  {
		vis[i][step]=1;
		return;
	  }
}
void bfs(int step,node start)
{
	memset(mark,0,sizeof(mark));
	queue<node>q;
	q.push(start);
	mark[start.x][start.y]=1;
	while (!q.empty())
	 {
		node u=q.front();
		q.pop();
		get(u.x,u.y,step);
		if (u.now==d)continue;
		for (int k=0;k<=3;k++)
		 {
			node v=(node){u.x+dx[k],u.y+dy[k],u.now+1};
			if (v.x<1||v.x>n||v.y<1||v.y>m||
			mark[v.x][v.y]||a[v.x][v.y])continue;
			mark[v.x][v.y]=1;
			q.push(v);
		 }
	 }
}
int main()
{
	freopen("input.txt","r",stdin);
	freopen("input.out","w",stdout);
	scanf("%d%d%d",&n,&m,&d);
	for(int i=1;i<=n;i++)
	 {
		scanf("%s",s[i]+1);
		for (int j=1;j<=m;j++)
		 {
			a[i][j]=0;
			if (s[i][j]=='R') rats[++cnt]=(node){i,j,0};
			if (s[i][j]=='X') a[i][j]=1;
		 }
	 }
	if (cnt>226)
	 {
		puts("-1");
		return 0;
	 }
	for (int i=1;i<=cnt;i++) bfs(i,rats[i]);
	if (sum==1)
	 {
		for (int i=1;i<=cnt;i++)
		 if (!vis[1][i])
		  {
			puts("-1");
			return 0;
		  }
		printf("%d %d ",x[1],y[1]);
		for (int i=1;i<=n;i++)
		 for (int j=1;j<=m;j++)
		  if (!a[i][j]&&(i!=x[1]||j!=y[1]))
		   {
			printf("%d %d",i,j);
			return 0;
		   }
	 }
	int flag;
	for (int i=1;i<sum;i++)
	 {
	 	for (int j=i+1;j<=sum;j++)
		 {
			flag=1;
			for (int k=1;k<=cnt;k++)
			 if (!vis[i][k]&&!vis[j][k])
			  {
				flag=0;
				break;
			  }
			if (flag)
			 {
				ans1=i,ans2=j;
				break;
			 }
		 }
		if (flag) break;
	 }
	if (flag)printf("%d %d %d %d",x[ans1],y[ans1],x[ans2],y[ans2]);
	else puts("-1");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1005;
const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
struct node{int x,y,now;}rats[N*N];
int n,m,d,cnt,sum,ans1,ans2,num[N][N],x[N],y[N],a[N][N];
char s[N][N];
int vis[N][N],mark[N][N];
void get(int xx,int yy,int step)
{
	if (!num[xx][yy])
	 {
		vis[++sum][step]=1;
		x[sum]=xx,y[sum]=yy;
		num[xx][yy]=1;
		return;
	 }
	for (int i=1;i<=sum;i++)
	 if (x[i]==xx&&y[i]==yy)
	  {
		vis[i][step]=1;
		return;
	  }
}
void bfs(int step,node start)
{
	memset(mark,0,sizeof(mark));
	queue<node>q;
	q.push(start);
	mark[start.x][start.y]=1;
	while (!q.empty())
	 {
		node u=q.front();
		q.pop();
		get(u.x,u.y,step);
		if (u.now==d)continue;
		for (int k=0;k<=3;k++)
		 {
			node v=(node){u.x+dx[k],u.y+dy[k],u.now+1};
			if (v.x<1||v.x>n||v.y<1||v.y>m||
			mark[v.x][v.y]||a[v.x][v.y])continue;
			mark[v.x][v.y]=1;
			q.push(v);
		 }
	 }
}
int main()
{
	scanf("%d%d%d",&n,&m,&d);
	for(int i=1;i<=n;i++)
	 {
		scanf("%s",s[i]+1);
		for (int j=1;j<=m;j++)
		 {
			a[i][j]=0;
			if (s[i][j]=='R') rats[++cnt]=(node){i,j,0};
			if (s[i][j]=='X') a[i][j]=1;
		 }
	 }
	if (cnt>226)
	 {
		puts("-1");
		return 0;
	 }
	for (int i=1;i<=cnt;i++) bfs(i,rats[i]);
	if (sum==1)
	 {
		for (int i=1;i<=cnt;i++)
		 if (!vis[1][i])
		  {
			puts("-1");
			return 0;
		  }
		printf("%d %d ",x[1],y[1]);
		for (int i=1;i<=n;i++)
		 for (int j=1;j<=m;j++)
		  if (!a[i][j]&&(i!=x[1]||j!=y[1]))
		   {
			printf("%d %d",i,j);
			return 0;
		   }
	 }
	int flag;
	for (int i=1;i<sum;i++)
	 {
	 	for (int j=i+1;j<=sum;j++)
		 {
			flag=1;
			for (int k=1;k<=cnt;k++)
			 if (!vis[i][k]&&!vis[j][k])
			  {
				flag=0;
				break;
			  }
			if (flag)
			 {
				ans1=i,ans2=j;
				break;
			 }
		 }
		if (flag) break;
	 }
	if (flag)printf("%d %d %d %d",x[ans1],y[ans1],x[ans2],y[ans2]);
	else puts("-1");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1005;
const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
struct node{int x,y,now;}rats[N*N];
int n,m,d,cnt,sum,ans1,ans2,num[N][N],x[N],y[N],a[N][N];
char s[N][N];
int vis[N][N],mark[N][N];
void get(int xx,int yy,int step)
{
	if (!num[xx][yy])
	 {
		vis[++sum][step]=1;
		x[sum]=xx,y[sum]=yy;
		num[xx][yy]=1;
		return;
	 }
	for (int i=1;i<=sum;i++)
	 if (x[i]==xx&&y[i]==yy)
	  {
		vis[i][step]=1;
		return;
	  }
}
void bfs(int step,node start)
{
	memset(mark,0,sizeof(mark));
	queue<node>q;
	q.push(start);
	mark[start.x][start.y]=1;
	while (!q.empty())
	 {
		node u=q.front();
		q.pop();
		get(u.x,u.y,step);
		if (u.now==d)continue;
		for (int k=0;k<=3;k++)
		 {
			node v=(node){u.x+dx[k],u.y+dy[k],u.now+1};
			if (v.x<1||v.x>n||v.y<1||v.y>m||
			mark[v.x][v.y]||a[v.x][v.y])continue;
			mark[v.x][v.y]=1;
			q.push(v);
		 }
	 }
}
int main()
{
	freopen("input.txt","r",stdin);
	freopen("input.txt","w",stdout);
	scanf("%d%d%d",&n,&m,&d);
	for(int i=1;i<=n;i++)
	 {
		scanf("%s",s[i]+1);
		for (int j=1;j<=m;j++)
		 {
			a[i][j]=0;
			if (s[i][j]=='R') rats[++cnt]=(node){i,j,0};
			if (s[i][j]=='X') a[i][j]=1;
		 }
	 }
	if (cnt>226)
	 {
		puts("-1");
		return 0;
	 }
	for (int i=1;i<=cnt;i++) bfs(i,rats[i]);
	if (sum==1)
	 {
		for (int i=1;i<=cnt;i++)
		 if (!vis[1][i])
		  {
			puts("-1");
			return 0;
		  }
		printf("%d %d ",x[1],y[1]);
		for (int i=1;i<=n;i++)
		 for (int j=1;j<=m;j++)
		  if (!a[i][j]&&(i!=x[1]||j!=y[1]))
		   {
			printf("%d %d",i,j);
			return 0;
		   }
	 }
	int flag;
	for (int i=1;i<sum;i++)
	 {
	 	for (int j=i+1;j<=sum;j++)
		 {
			flag=1;
			for (int k=1;k<=cnt;k++)
			 if (!vis[i][k]&&!vis[j][k])
			  {
				flag=0;
				break;
			  }
			if (flag)
			 {
				ans1=i,ans2=j;
				break;
			 }
		 }
		if (flag) break;
	 }
	if (flag)printf("%d %d %d %d",x[ans1],y[ans1],x[ans2],y[ans2]);
	else puts("-1");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1005;
const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
struct node{int x,y,now;}rats[N*N];
int n,m,d,cnt,sum,ans1,ans2,num[N][N],x[N],y[N],a[N][N];
char s[N][N];
int vis[N][N],mark[N][N];
void get(int xx,int yy,int step)
{
	if (!num[xx][yy])
	 {
		vis[++sum][step]=1;
		x[sum]=xx,y[sum]=yy;
		num[xx][yy]=1;
		return;
	 }
	for (int i=1;i<=sum;i++)
	 if (x[i]==xx&&y[i]==yy)
	  {
		vis[i][step]=1;
		return;
	  }
}
void bfs(int step,node start)
{
	memset(mark,0,sizeof(mark));
	queue<node>q;
	q.push(start);
	mark[start.x][start.y]=1;
	while (!q.empty())
	 {
		node u=q.front();
		q.pop();
		get(u.x,u.y,step);
		if (u.now==d)continue;
		for (int k=0;k<=3;k++)
		 {
			node v=(node){u.x+dx[k],u.y+dy[k],u.now+1};
			if (v.x<1||v.x>n||v.y<1||v.y>m||
			mark[v.x][v.y]||a[v.x][v.y])continue;
			mark[v.x][v.y]=1;
			q.push(v);
		 }
	 }
}
int main()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	scanf("%d%d%d",&n,&m,&d);
	for(int i=1;i<=n;i++)
	 {
		scanf("%s",s[i]+1);
		for (int j=1;j<=m;j++)
		 {
			a[i][j]=0;
			if (s[i][j]=='R') rats[++cnt]=(node){i,j,0};
			if (s[i][j]=='X') a[i][j]=1;
		 }
	 }
	if (cnt>226)
	 {
		puts("-1");
		return 0;
	 }
	for (int i=1;i<=cnt;i++) bfs(i,rats[i]);
	if (sum==1)
	 {
		for (int i=1;i<=cnt;i++)
		 if (!vis[1][i])
		  {
			puts("-1");
			return 0;
		  }
		printf("%d %d ",x[1],y[1]);
		for (int i=1;i<=n;i++)
		 for (int j=1;j<=m;j++)
		  if (!a[i][j]&&(i!=x[1]||j!=y[1]))
		   {
			printf("%d %d",i,j);
			return 0;
		   }
	 }
	int flag;
	for (int i=1;i<sum;i++)
	 {
	 	for (int j=i+1;j<=sum;j++)
		 {
			flag=1;
			for (int k=1;k<=cnt;k++)
			 if (!vis[i][k]&&!vis[j][k])
			  {
				flag=0;
				break;
			  }
			if (flag)
			 {
				ans1=i,ans2=j;
				break;
			 }
		 }
		if (flag) break;
	 }
	if (flag)printf("%d %d %d %d",x[ans1],y[ans1],x[ans2],y[ans2]);
	else puts("-1");
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<fstream>
#include<map>
#include<ctime>
#include<set>
#include<queue>
#include<cmath>
#include<vector>
#include<bitset>
#include<functional>
#define x first
#define y second
#define mp make_pair
#define pb push_back
using namespace std;

typedef long long LL;
typedef double ld;

const int MAX=1000+10;
const int NUM=300;

int walk[4][2]={{1,0},{0,1},{0,-1},{-1,0}};
int n,m,d,hash[MAX][MAX],dist[MAX][MAX];
char g[MAX][MAX];
int q[NUM];
vector<int> go[NUM];

int get(int a,int b)
{
	return (a-1)*m+b;
}

queue< pair<int,int> > que;

void dfs(int x,int y,int u)
{
	int i;
	que.push(mp(x,y));
	dist[x][y]=0;hash[x][y]=u;
	while(!que.empty())
	{
		pair<int,int> cc=que.front();que.pop();
		go[u].pb(get(cc.x,cc.y));
		if(dist[cc.x][cc.y]==d)continue;
		for(i=0;i<4;++i)
		{
			pair<int,int> v=mp(cc.x+walk[i][0],cc.y+walk[i][1]);
			if(hash[v.x][v.y]!=u && g[v.x][v.y]!='X')
			{
				hash[v.x][v.y]=u;
				dist[v.x][v.y]=dist[cc.x][cc.y]+1;
				que.push(v);
			}
		}
	}
	return;
}

int Judge(int a)
{
	int i,j,k=0,allcan=1;
	vector<int> now,last;
	for(i=1;i<=q[0];++i)
	{
		int flag=0;
		for(j=0;j<(int)go[i].size();++j)
			if(go[i][j]==a)
				flag=1;
		if(flag)continue;
		allcan=0;
		if((int)now.size()==0)
		{
			now=go[i];
			continue;
		}
		last.clear();
		k=0;
		for(j=0;j<(int)go[i].size();++j)
		{
			while( k<(int) now.size() && now[k]<go[i][j])++k;
			if(k<(int)now.size() && now[k]==go[i][j])
				last.pb(now[k]);
		}
		now=last;
		if((int)now.size()==0)
			return 0;
	}
	now.pb(0);
	if(allcan)
	{
		now[0]=0;
		for(i=1;i<=n;++i)
			for(j=1;j<=m;++j)
				if(g[i][j]!='X' && get(i,j)!=a)
					now[0]=get(i,j);
		if(!now[0])return 0;
	 }
	printf("%d %d %d %d\n",(a-1)/m+1,(a-1)%m+1,(now[0]-1)/m+1,(now[0]-1)%m+1);
	return 1;
}

int main()
{
	freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	int i,j;
	scanf("%d%d%d",&n,&m,&d);
	int maxR=(2*d+1+1)*(d+1)/2+(2*d-1+1)*d/2;
	for(i=1;i<=n;++i)
		scanf("%s",g[i]+1);
	int all=0;
	for(i=1;i<=n;++i)
		for(j=1;j<=m;++j)
			if(g[i][j]=='R')
				++all;
	if(all>maxR*2)
	{
		printf("-1\n");
		return 0;
	}
	for(i=1;i<=n;++i)
		for(j=1;j<=m;++j)
			if(g[i][j]=='R')
			{
				q[++q[0]]=get(i,j);
				dfs(i,j,q[0]);
				sort(go[q[0]].begin(),go[q[0]].end());
			}
	for(i=1;i<=n;++i)
		for(j=1;j<=m;++j)
			if(hash[i][j] && Judge(get(i,j)))
				return 0;
	printf("-1\n");
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<fstream>
#include<map>
#include<ctime>
#include<set>
#include<queue>
#include<cmath>
#include<vector>
#include<bitset>
#include<functional>
#define x first
#define y second
#define mp make_pair
#define pb push_back
using namespace std;

typedef long long LL;
typedef double ld;

const int MAX=1000+10;
const int NUM=300;

int walk[4][2]={{1,0},{0,1},{0,-1},{-1,0}};
int n,m,d,hash[MAX][MAX],dist[MAX][MAX];
char g[MAX][MAX];
int q[NUM];
vector<int> go[NUM];

int get(int a,int b)
{
	return (a-1)*m+b;
}

queue< pair<int,int> > que;

void dfs(int x,int y,int u)
{
	int i;
	que.push(mp(x,y));
	dist[x][y]=0;hash[x][y]=u;
	while(!que.empty())
	{
		pair<int,int> cc=que.front();que.pop();
		go[u].pb(get(cc.x,cc.y));
		if(dist[cc.x][cc.y]==d)continue;
		for(i=0;i<4;++i)
		{
			pair<int,int> v=mp(cc.x+walk[i][0],cc.y+walk[i][1]);
			if(hash[v.x][v.y]!=u && g[v.x][v.y]!='X')
			{
				hash[v.x][v.y]=u;
				dist[v.x][v.y]=dist[cc.x][cc.y]+1;
				que.push(v);
			}
		}
	}
	return;
}

int Judge(int a)
{
	int i,j,k=0,allcan=1;
	vector<int> now,last;
	for(i=1;i<=q[0];++i)
	{
		int flag=0;
		for(j=0;j<(int)go[i].size();++j)
			if(go[i][j]==a)
				flag=1;
		if(flag)continue;
		allcan=0;
		if((int)now.size()==0)
		{
			now=go[i];
			continue;
		}
		last.clear();
		k=0;
		for(j=0;j<(int)go[i].size();++j)
		{
			while( k<(int) now.size() && now[k]<go[i][j])++k;
			if(k<(int)now.size() && now[k]==go[i][j])
				last.pb(now[k]);
		}
		now=last;
		if((int)now.size()==0)
			return 0;
	}
	if(!allcan)printf("%d %d %d %d\n",(a-1)/m+1,(a-1)%m+1,(now[0]-1)/m+1,(now[0]-1)%m+1);
	else printf("%d %d %d %d\n",(a-1)/m+1,(a-1)%m+1,(a-1)/m+1,(a-1)%m+1);
	return 1;
}

int main()
{
	freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	int i,j;
	scanf("%d%d%d",&n,&m,&d);
	int maxR=(2*d+1+1)*(d+1)/2+(2*d-1+1)*d/2;
	for(i=1;i<=n;++i)
		scanf("%s",g[i]+1);
	int all=0;
	for(i=1;i<=n;++i)
		for(j=1;j<=m;++j)
			if(g[i][j]=='R')
				++all;
	if(all>maxR*2)
	{
		printf("-1\n");
		return 0;
	}
	for(i=1;i<=n;++i)
		for(j=1;j<=m;++j)
			if(g[i][j]=='R')
			{
				q[++q[0]]=get(i,j);
				dfs(i,j,q[0]);
				sort(go[q[0]].begin(),go[q[0]].end());
			}
	for(i=1;i<=n;++i)
		for(j=1;j<=m;++j)
			if(hash[i][j] && Judge(get(i,j)))
				return 0;
	printf("-1\n");
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<fstream>
#include<map>
#include<ctime>
#include<set>
#include<queue>
#include<cmath>
#include<vector>
#include<bitset>
#include<functional>
#define x first
#define y second
#define mp make_pair
#define pb push_back
using namespace std;

typedef long long LL;
typedef double ld;

const int MAX=1000+10;
const int NUM=300;

int walk[4][2]={{1,0},{0,1},{0,-1},{-1,0}};
int n,m,d,hash[MAX][MAX],dist[MAX][MAX];
char g[MAX][MAX];
int q[NUM];
vector<int> go[NUM];

int get(int a,int b)
{
	return (a-1)*m+b;
}

queue< pair<int,int> > que;

void dfs(int x,int y,int u)
{
	int i;
	que.push(mp(x,y));
	dist[x][y]=0;hash[x][y]=u;
	while(!que.empty())
	{
		pair<int,int> cc=que.front();que.pop();
		go[u].pb(get(cc.x,cc.y));
		if(dist[cc.x][cc.y]==d)continue;
		for(i=0;i<4;++i)
		{
			pair<int,int> v=mp(cc.x+walk[i][0],cc.y+walk[i][1]);
			if(hash[v.x][v.y]!=u && g[v.x][v.y]!='X')
			{
				hash[v.x][v.y]=u;
				dist[v.x][v.y]=dist[cc.x][cc.y]+1;
				que.push(v);
			}
		}
	}
	return;
}

int Judge(int a)
{
	int i,j,k=0,allcan=1;
	vector<int> now,last;
	for(i=1;i<=q[0];++i)
	{
		int flag=0;
		for(j=0;j<(int)go[i].size();++j)
			if(go[i][j]==a)
				flag=1;
		if(flag)continue;
		allcan=0;
		if((int)now.size()==0)
		{
			now=go[i];
			continue;
		}
		last.clear();
		k=0;
		for(j=0;j<(int)go[i].size();++j)
		{
			while( k<(int) now.size() && now[k]<go[i][j])++k;
			if(k<(int)now.size() && now[k]==go[i][j])
				last.pb(now[k]);
		}
		now=last;
		if((int)now.size()==0)
			return 0;
	}
	now.pb(0);
	if(allcan)
	{
		now[0]=0;
		for(i=1;i<=n;++i)
			for(j=1;j<=n;++j)
				if(g[i][j]!='X' && get(i,j)!=a)
					now[0]=get(i,j);
		if(!now[0])return 0;
	 }
	printf("%d %d %d %d\n",(a-1)/m+1,(a-1)%m+1,(now[0]-1)/m+1,(now[0]-1)%m+1);
	return 1;
}

int main()
{
	freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	int i,j;
	scanf("%d%d%d",&n,&m,&d);
	int maxR=(2*d+1+1)*(d+1)/2+(2*d-1+1)*d/2;
	for(i=1;i<=n;++i)
		scanf("%s",g[i]+1);
	int all=0;
	for(i=1;i<=n;++i)
		for(j=1;j<=m;++j)
			if(g[i][j]=='R')
				++all;
	if(all>maxR*2)
	{
		printf("-1\n");
		return 0;
	}
	for(i=1;i<=n;++i)
		for(j=1;j<=m;++j)
			if(g[i][j]=='R')
			{
				q[++q[0]]=get(i,j);
				dfs(i,j,q[0]);
				sort(go[q[0]].begin(),go[q[0]].end());
			}
	for(i=1;i<=n;++i)
		for(j=1;j<=m;++j)
			if(hash[i][j] && Judge(get(i,j)))
				return 0;
	printf("-1\n");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct PAIR {
	int first,second;
	PAIR(int x=0, int y=0) {
		first=x;
		second=y;
	}
	bool operator == (PAIR xx) {
		return first==xx.first && second==xx.second;
	}
	bool operator != (PAIR xx) {
		return first!=xx.first || second!=xx.second;
	}
	void operator = (PAIR xx) {
		first=xx.first;
		second=xx.second;
	}
};
typedef PAIR pii;

#define RAT 0
#define BOMB 1
const int N=1005,M=305;
int n,m,d;
bool dead[M];
char s[N][N];
int mp[N][N];
int dis[N][N];
bool record[M];

const int dx[]={-1,1,0,0};
const int dy[]={0,0,-1,1};

pii que[N];
int quel,quer;

void bfs(pii st,bool br,pii v[],int &sz) {
	memset(dis,-1,sizeof(dis));
	sz=0;
	quel=quer=0;
	int sx=st.first,sy=st.second;
	dis[sx][sy]=0;
	if (br==BOMB) {
		if (s[sx][sy]=='R') {
			dead[mp[sx][sy]]=1;
		}
	}
	v[sz++]=pii(sx,sy);
	que[quer++]=pii(sx,sy);
	while (quel<quer) {
		pii now=que[quel++];
		int x=now.first,y=now.second;
		if (dis[x][y]>d) {
			return;
		}
		for(int dir=0;dir<4;dir++) {
			int nx=x+dx[dir],ny=y+dy[dir];
			if (s[nx][ny]=='X'||~dis[nx][ny]) {
				continue;
			}
			dis[nx][ny]=dis[x][y]+1;
			if (dis[nx][ny]>d) {
				return;
			}
			v[sz++]=pii(nx,ny);
			if (br==BOMB) {
				if (s[nx][ny]=='R') {
					dead[mp[nx][ny]]=1;
				}
			}
			que[quer++]=pii(nx,ny);
		}
	}
}

pii rats[N*N],rats1[M],rats2[M],bomb1[M],bomb2[M];
int szr,szr1,szr2,szb1,szb2;

inline void printans(pii a,pii b) {
	printf("%d %d %d %d\n",a.first+1,a.second+1,b.first+1,b.second+1);
}

int main() {
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#ifdef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	scanf("%d%d%d",&n,&m,&d);
	for(int i=0;i<n;i++) scanf("%s",s[i]);
	for(int i=0;i<n;i++) {
		for(int j=0;j<m;j++) {
			if (s[i][j]=='R') {
				rats[szr]=pii(i,j);
				mp[i][j]=szr++;
			}
		}
	}
	if (szr>290) {
		printf("-1\n");
		return 0;
	}
	bfs(rats[0],RAT,bomb1,szb1);
	for(int i=0;i<szb1;i++) {
		pii firstbomb=bomb1[i];
//		printf("%d %d\n",firstbomb.first,firstbomb.second);
		memset(dead,0,sizeof(dead));
		bfs(firstbomb,BOMB,rats1,szr1);
		for(int j=0;j<szr;j++) {
			record[j]=dead[j];
		}
		pii rat2=pii(-1,-1);
		for(int j=0;j<szr;j++) {
			if (!dead[j]) {
				rat2=rats[j];
				break;
			}
		}
		if (rat2==pii(-1,-1)) {
			pii secondbomb=pii(-1,-1);
			for(int i=1;i<n-1;i++) {
				for(int j=1;j<m-1;j++) {
					if (pii(i,j)!=firstbomb&&s[i][j]!='X') {
						secondbomb=pii(i,j);
						break;
					}
				}
				if (secondbomb!=pii(-1,-1)) {
					break;
				}
			}
			printans(firstbomb,secondbomb);
			return 0;
		}
		bfs(rat2,RAT,bomb2,szb2);
		for(int j=0;j<szb2;j++) {
			pii secondbomb=bomb2[j];
			for(int k=0;k<szr;k++) {
				dead[k]=record[k];
			}
//			printf("\t%d %d\n",secondbomb.first,secondbomb.second);
			bfs(secondbomb,BOMB,rats2,szr2);
			bool flag=true;
			for(int k=0;k<szr;k++) {
				if (!dead[k]) {
					flag=false;
					break;
				}
			}
			if (flag) {
				printans(firstbomb,secondbomb);
				return 0;
			}
		}
	}
	printf("-1\n");
	return 0;
}


#pragma -O2

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct PAIR {
	int first,second;
	PAIR(int x=0, int y=0) {
		first=x;
		second=y;
	}
	bool operator == (PAIR xx) {
		return first==xx.first && second==xx.second;
	}
	bool operator != (PAIR xx) {
		return first!=xx.first || second!=xx.second;
	}
	void operator = (PAIR xx) {
		first=xx.first;
		second=xx.second;
	}
};
typedef PAIR pii;

#define RAT 0
#define BOMB 1
const int N=1005,M=305;
int n,m,d;
bool dead[M];
char s[N][N];
int mp[N][N];
int dis[N][N];
bool record[M];

const int dx[]={-1,1,0,0};
const int dy[]={0,0,-1,1};

pii que[N];
int quel,quer;

void bfs(pii st,bool br,pii *v,int &sz) {
	memset(dis,-1,sizeof(dis));
	sz=0;
	quel=quer=0;
	register int sx=st.first,sy=st.second;
	dis[sx][sy]=0;
	if (br==BOMB) {
		if (s[sx][sy]=='R') {
			dead[mp[sx][sy]]=1;
		}
	}
	v[sz++]=pii(sx,sy);
	que[quer++]=pii(sx,sy);
	while (quel<quer) {
		pii now=que[quel++];
		register int x=now.first,y=now.second;
		for(int dir=0;dir<4;dir++) {
			register int nx=x+dx[dir],ny=y+dy[dir];
			if (s[nx][ny]=='X'||~dis[nx][ny]) {
				continue;
			}
			dis[nx][ny]=dis[x][y]+1;
			if (dis[nx][ny]>d) {
				return;
			}
			v[sz++]=pii(nx,ny);
			if (br==BOMB) {
				if (s[nx][ny]=='R') {
					dead[mp[nx][ny]]=1;
				}
			}
			que[quer++]=pii(nx,ny);
		}
	}
}

pii rats[N*N],rats1[M],rats2[M],bomb1[M],bomb2[M];
int szr,szr1,szr2,szb1,szb2;

inline void printans(pii a,pii b) {
	printf("%d %d %d %d\n",a.first+1,a.second+1,b.first+1,b.second+1);
}

int main() {
#ifdef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	scanf("%d%d%d",&n,&m,&d);
	for(int i=0;i<n;i++) scanf("%s",s[i]);
	for(int i=0;i<n;i++) {
		for(int j=0;j<m;j++) {
			if (s[i][j]=='R') {
				rats[szr]=pii(i,j);
				mp[i][j]=szr++;
			}
		}
	}
	if (szr>290) {
		printf("-1\n");
		return 0;
	}
	bfs(rats[0],RAT,bomb1,szb1);
	for(int i=0;i<szb1;i++) {
		pii firstbomb=bomb1[i];
//		printf("%d %d\n",firstbomb.first,firstbomb.second);
		memset(dead,0,sizeof(dead));
		bfs(firstbomb,BOMB,rats1,szr1);
		for(int j=0;j<szr;j++) {
			record[j]=dead[j];
		}
		pii rat2(-1,-1);
		for(int j=0;j<szr;j++) {
			if (!dead[j]) {
				rat2=rats[j];
				break;
			}
		}
		if (rat2==pii(-1,-1)) {
			pii secondbomb(-1,-1);
			for(int i=1;i<n-1;i++) {
				for(int j=1;j<m-1;j++) {
					if (pii(i,j)!=firstbomb&&s[i][j]!='X') {
						secondbomb=pii(i,j);
						break;
					}
				}
				if (secondbomb!=pii(-1,-1)) {
					break;
				}
			}
			printans(firstbomb,secondbomb);
			return 0;
		}
		bfs(rat2,RAT,bomb2,szb2);
		for(int j=0;j<szb2;j++) {
			pii secondbomb=bomb2[j];
			for(int k=0;k<szr;k++) {
				dead[k]=record[k];
			}
//			printf("\t%d %d\n",secondbomb.first,secondbomb.second);
			bfs(secondbomb,BOMB,rats2,szr2);
			bool flag(true);
			for(int k=0;k<szr;k++) {
				if (!dead[k]) {
					flag=false;
					break;
				}
			}
			if (flag) {
				printans(firstbomb,secondbomb);
				return 0;
			}
		}
	}
	printf("-1\n");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

#define RAT 0
#define BOMB 1
const int N=1005,M=305;
char s[N][N];
set<pii> rats;
int szr1,szr2,szb1,szb2,i,j,k,quel,quer,dis[N][N],n,m,d;
pii rats1[M],rats2[M],bomb1[M],bomb2[M],rat1,rat2,que[M];

const int dx[]={-1,0,0,1};
const int dy[]={0,-1,1,0};

void bfs(pii st,bool br,pii *v,int &sz) {
	memset(dis,-1,sizeof(dis));
	sz=0;
	quel=quer=0;
	int sx=st.first,sy=st.second,x,y,nx,ny,dir;
	dis[sx][sy]=0;
	que[quer++]=pii(sx,sy);
	while (quel<quer) {
		pii now=que[quel++];
		x=now.first,y=now.second;
		if (br!=BOMB||rats.count(pii(x,y))) {
			v[sz++]=pii(x,y);
			if (br==BOMB) rats.erase(pii(x,y));
		}
		if (dis[x][y]==d) continue;
		for(dir=0;dir<4;dir++) {
			nx=x+dx[dir],ny=y+dy[dir];
			if (s[nx][ny]=='X'||~dis[nx][ny]) {
				continue;
			}
			dis[nx][ny]=dis[x][y]+1;
			que[quer++]=pii(nx,ny);
		}
	}
	sort(v,v+sz);
}

int main() {
#ifdef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	scanf("%d%d%d",&n,&m,&d);
	for(i=0;i<n;i++) scanf("%s",s[i]);
	for(i=0;i<n;i++) for(j=0;j<m;j++) if (s[i][j]=='R') rats.insert(pii(i,j));
	rat1=*rats.begin();
	bfs(rat1,RAT,bomb1,szb1);
	for(i=0;i<szb1;i++) {
		bfs(bomb1[i],BOMB,rats1,szr1);
		rat2=pii(-1,-1);
		if (!rats.empty()) rat2=*rats.begin();
		if (rat2==pii(-1,-1)) for(j=1;j<n-1;j++) for(k=1;k<m-1;k++)
			if (pii(j,k)!=bomb1[i]&&s[j][k]!='X') {
				printf("%d %d %d %d\n",bomb1[i].first+1,bomb1[i].second+1,j+1,k+1);
				return 0;
			}
		bfs(rat2,RAT,bomb2,szb2);
		for(j=0;j<szb2;j++) {
			bfs(bomb2[j],BOMB,rats2,szr2);
			if (rats.empty()) {
				printf("%d %d %d %d\n",bomb1[i].first+1,bomb1[i].second+1,bomb2[j].first+1,bomb2[j].second+1);
				return 0;
			}
			for(k=0;k<szr2;k++) rats.insert(rats2[k]);
		}
		for(j=0;j<szr1;j++) rats.insert(rats1[j]);
	}
	printf("-1\n");
	return 0;
}


#pragma -O2

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct PAIR {
	int first,second;
	PAIR(int x=0, int y=0) {
		first=x;
		second=y;
	}
	bool operator == (const PAIR &xx) const{
		return first==xx.first && second==xx.second;
	}
	bool operator != (const PAIR &xx) const{
		return first!=xx.first || second!=xx.second;
	}
	void operator = (const PAIR &xx){
		first=xx.first;
		second=xx.second;
	}
	bool operator < (const PAIR &xx) const {
		if (first!=xx.first) return first<xx.first;
		return second<xx.second;
	}
};
typedef PAIR pii;

#define RAT 0
#define BOMB 1
const int N=1005,M=305;
int n,m,d;
char s[N][N];
int dis[N][N];

const int dx[]={-1,0,0,1};
const int dy[]={0,-1,1,0};

pii que[N];
int quel,quer;

set<pii> rats;

void bfs(pii st,bool br,pii *v,int &sz) {
	memset(dis,-1,sizeof(dis));
	sz=0;
	quel=quer=0;
	int sx=st.first,sy=st.second,x,y,nx,ny,dir;
	dis[sx][sy]=0;
	que[quer++]=pii(sx,sy);
	while (quel<quer) {
		pii now=que[quel++];
		x=now.first,y=now.second;
		if (br==BOMB) {
			if (s[x][y]=='R') {
				if (rats.count(pii(x,y))) {
					v[sz++]=pii(x,y);
					rats.erase(pii(x,y));
				}
			}
		} else {
			v[sz++]=pii(x,y);
		}
		if (dis[x][y]==d) continue;
		for(dir=0;dir<4;dir++) {
			nx=x+dx[dir],ny=y+dy[dir];
			if (s[nx][ny]=='X'||~dis[nx][ny]) {
				continue;
			}
			dis[nx][ny]=dis[x][y]+1;
			que[quer++]=pii(nx,ny);
		}
	}
	sort(v,v+sz);
}

pii rats1[M],rats2[M],bomb1[M],bomb2[M];
int szr1,szr2,szb1,szb2;

int main() {
#ifdef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	scanf("%d%d%d",&n,&m,&d);
	pii rat2;
	int i,j,k;
	for(int i=0;i<n;i++) scanf("%s",s[i]);
	for(int i=0;i<n;i++) {
		for(int j=0;j<m;j++) {
			if (s[i][j]=='R') {
				rats.insert(pii(i,j));
			}
		}
	}
	if ((int)rats.size()>290) {
		printf("-1\n");
		return 0;
	}
	bfs(*rats.begin(),RAT,bomb1,szb1);
	for(i=0;i<szb1;i++) {
		#define firstbomb bomb1[i]
//		printf("%d %d\n",firstbomb.first,firstbomb.second);
		bfs(firstbomb,BOMB,rats1,szr1);
		rat2=pii(-1,-1);
		if (!rats.empty()) rat2=*rats.begin();
		if (rat2==pii(-1,-1)) {
			for(j=1;j<n-1;j++) {
				for(k=1;k<m-1;k++) {
					if (pii(j,k)!=firstbomb&&s[j][k]!='X') {
						printf("%d %d %d %d\n",firstbomb.first+1,firstbomb.second+1,j+1,k+1);
						return 0;
					}
				}
			}
		}
		bfs(rat2,RAT,bomb2,szb2);
		for(j=0;j<szb2;j++) {
			#define secondbomb bomb2[j]
//			printf("\t%d %d\n",secondbomb.first,secondbomb.second);
			bfs(secondbomb,BOMB,rats2,szr2);
//			if (firstbomb==pii(4,5)&&secondbomb==pii(3,9)) {
//				for(auto xx:rats) {
//					printf("(%d,%d)",xx.first,xx.second);
//				}
//				printf("\n");
//			}
			if (rats.empty()) {
				printf("%d %d %d %d\n",firstbomb.first+1,firstbomb.second+1,secondbomb.first+1,secondbomb.second+1);
				return 0;
			}
			for(k=0;k<szr2;k++) if (s[rats2[k].first][rats2[k].second]=='R') rats.insert(rats2[k]);
		}
		for(j=0;j<szr1;j++) if (s[rats1[j].first][rats1[j].second]=='R') rats.insert(rats1[j]);
	}
	printf("-1\n");
	return 0;
}


#include <set>
#include <map>
#include <queue>
#include <deque>
#include <cstdio>
#include <string>
#include <vector>
#include <math.h>
#include <time.h>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <stdio.h>
#include <iomanip>
#include <conio.h>
#include <iostream>
#include <algorithm>
#define max(a,b) (b<a ? a : b)
#define min(a,b) (a<b ? a : b)
#define FAST() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
int dx[]={0,0,-1,1},dy[]={-1,1,0,0};
struct point {
	int x,y;
	point(int X=0,int Y=0) {
		x=X,y=Y;
	}
	~point() {
	}
};
int n,m,d;
char c[1005][1005];
vector<point> rats;
int beat[1005][1005];
vector<point> get_neighbour(int sx,int sy,int val=0) {
	queue<int> q;
	vector<point> v;
	q.push(sx);q.push(sy);q.push(0);
	while (!q.empty()) {
		int x = q.front();q.pop();
		int y = q.front();q.pop();
		beat[x][y]+=val;
		v.push_back(point(x,y));
		int dis = q.front();q.pop();
		if (dis > d) break;
		for (int i = 0;i < 4;i++) {
			int nx = x+dx[i],ny=y+dy[i];
			if (nx>0 && ny>0 && nx<=n && ny<=m && c[nx][ny]!='X') {
				q.push(nx);q.push(ny);q.push(dis+1);
			}
		}
	}
	return v;
}
int main() {
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	scanf("%d%d%d", &n, &m, &d);
	for (int i = 1;i <= n;i++)
		for (int j = 1;j <= m;j++) {
			scanf("%c", &c[i][j]);
			if (c[i][j]=='R')
				rats.push_back(point(i,j));
		}
	if ((int)rats.size() > 300) {
		printf("-1");
		return 0;
	}
	int x = rats[0].x,y = rats[0].y;
	vector<point> v = get_neighbour(x,y);
	for (int i = 0;i < (int)v.size();i++) {
		int sx = v[i].x,sy=v[i].y;
//		cout << sx << " " << sy << endl;
		vector<point> v1 = get_neighbour(sx,sy);
		for (int k = 0;k < (int)v1.size();k++)
			beat[v1[k].x][v1[k].y]++;
		int s;
		for (s = 0;s < (int)rats.size();s++)
			if (!beat[rats[s].x][rats[s].y]) break;
		if (s == (int)rats.size()) {
			for (int j = 1;j <= n;j++) for (int k = 1;k <= m;k++)
				if (c[j][k]!='X' && !(j==sx && k==sy)) {
					printf("%d %d %d %d", x, y, j, k);
					return 0;
				}
		}
		x = rats[s].x,y = rats[s].y;
		vector <point> v2 = get_neighbour(x,y);
		for (int j = 0;j < (int)v2.size();j++) {
			int xx = v2[j].x,yy = v2[j].y;
			get_neighbour(xx,yy,1);
			bool f = true;
			for (int k = 0;k < (int)rats.size();k++)
				if (!beat[rats[k].x][rats[k].y]) f=false;
			if (f) {
				printf("%d %d %d %d", xx, yy, sx, sy);
				return 0;
			}
			get_neighbour(xx,yy,-1);
		}
		for (int k = 0;k < (int)v1.size();k++)
			beat[v1[k].x][v1[k].y]--;
	}
	printf("-1");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct PAIR {
	int first,second;
	PAIR(int x=0, int y=0) {
		first=x;
		second=y;
	}
	bool operator == (PAIR xx) {
		return first==xx.first && second==xx.second;
	}
	bool operator != (PAIR xx) {
		return first!=xx.first || second!=xx.second;
	}
	void operator = (PAIR xx) {
		first=xx.first;
		second=xx.second;
	}
};
typedef PAIR pii;

#define RAT 0
#define BOMB 1
const int N=1005,M=305;
int n,m,d;
bool dead[M];
char s[N][N];
int mp[N][N];
int dis[N][N];
bool record[M];

const int dx[]={-1,1,0,0};
const int dy[]={0,0,-1,1};

pii que[N];
int quel,quer;

void bfs(pii st,bool br,pii v[],int &sz) {
	memset(dis,-1,sizeof(dis));
	sz=0;
	quel=quer=0;
	int sx=st.first,sy=st.second;
	dis[sx][sy]=0;
	if (br==BOMB) {
		if (s[sx][sy]=='R') {
			dead[mp[sx][sy]]=1;
		}
	}
	v[sz++]=pii(sx,sy);
	que[quer++]=pii(sx,sy);
	while (quel<quer) {
		pii now=que[quel++];
		int x=now.first,y=now.second;
		if (dis[x][y]>d) {
			return;
		}
		for(int dir=0;dir<4;dir++) {
			int nx=x+dx[dir],ny=y+dy[dir];
			if (nx<0||ny<0||nx>=n||ny>=m||s[nx][ny]=='X'||~dis[nx][ny]) {
				continue;
			}
			dis[nx][ny]=dis[x][y]+1;
			if (dis[nx][ny]>d) {
				return;
			}
			v[sz++]=pii(nx,ny);
			if (br==BOMB) {
				if (s[nx][ny]=='R') {
					dead[mp[nx][ny]]=1;
				}
			}
			que[quer++]=pii(nx,ny);
		}
	}
}

pii rats[N*N],rats1[M],rats2[M],bomb1[M],bomb2[M];
int szr,szr1,szr2,szb1,szb2;

inline void printans(pii a,pii b) {
	printf("%d %d %d %d\n",a.first+1,a.second+1,b.first+1,b.second+1);
}

int main() {
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#ifdef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	scanf("%d%d%d",&n,&m,&d);
	for(int i=0;i<n;i++) scanf("%s",s[i]);
	for(int i=0;i<n;i++) {
		for(int j=0;j<m;j++) {
			if (s[i][j]=='R') {
				rats[szr++]=pii(i,j);
				mp[i][j]=szr-1;
			}
		}
	}
	if (szr>290) {
		printf("-1\n");
		return 0;
	}
	bfs(rats[0],RAT,bomb1,szb1);
	for(int i=0;i<szb1;i++) {
		pii firstbomb=bomb1[i];
//		printf("%d %d\n",firstbomb.first,firstbomb.second);
		memset(dead,0,sizeof(dead));
		bfs(firstbomb,BOMB,rats1,szr1);
		for(int j=0;j<szr1;j++) {
			record[j]=dead[j];
		}
		pii rat2=pii(-1,-1);
		for(int j=0;j<szr;j++) {
			if (!dead[j]) {
				rat2=rats[j];
				break;
			}
		}
		if (rat2==pii(-1,-1)) {
			pii secondbomb=pii(-1,-1);
			for(int i=1;i<n-1;i++) {
				for(int j=1;j<m-1;j++) {
					if (pii(i,j)!=firstbomb&&s[i][j]!='X') {
						secondbomb=pii(i,j);
						break;
					}
				}
				if (secondbomb!=pii(-1,-1)) {
					break;
				}
			}
			printans(firstbomb,secondbomb);
			return 0;
		}
		bfs(rat2,RAT,bomb2,szb2);
		for(int j=0;j<szb2;j++) {
			pii secondbomb=bomb2[j];
			for(int k=0;k<szr;k++) {
				dead[k]=record[k];
			}
//			printf("\t%d %d\n",secondbomb.first,secondbomb.second);
			bfs(secondbomb,BOMB,rats2,szr2);
			bool flag=true;
			for(int k=0;k<szr;k++) {
				if (!dead[k]) {
					flag=false;
					break;
				}
			}
			if (flag) {
				printans(firstbomb,secondbomb);
				return 0;
			}
		}
	}
	printf("-1\n");
	return 0;
}


#pragma -O2

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct PAIR {
	int first,second;
	PAIR(int x=0, int y=0) {
		first=x;
		second=y;
	}
	bool operator == (const PAIR &xx) const{
		return first==xx.first && second==xx.second;
	}
	bool operator != (const PAIR &xx) const{
		return first!=xx.first || second!=xx.second;
	}
	void operator = (const PAIR &xx){
		first=xx.first;
		second=xx.second;
	}
	bool operator < (const PAIR &xx) const {
		if (first!=xx.first) return first<xx.first;
		return second<xx.second;
	}
};
typedef PAIR pii;

#define RAT 0
#define BOMB 1
const int N=1005,M=305;
int n,m,d;
char s[N][N];
int dis[N][N];

const int dx[]={-1,0,0,1};
const int dy[]={0,-1,1,0};

pii que[N];
int quel,quer;

set<pii> rats;

void bfs(pii st,bool br,pii *v,int &sz) {
	memset(dis,-1,sizeof(dis));
	sz=0;
	quel=quer=0;
	int sx=st.first,sy=st.second,x,y,nx,ny,dir;
	dis[sx][sy]=0;
	que[quer++]=pii(sx,sy);
	while (quel<quer) {
		pii now=que[quel++];
		x=now.first,y=now.second;
		if (br!=BOMB||rats.count(pii(x,y))) {
			v[sz++]=pii(x,y);
			if (br==BOMB) rats.erase(pii(x,y));
		}
		if (dis[x][y]==d) continue;
		for(dir=0;dir<4;dir++) {
			nx=x+dx[dir],ny=y+dy[dir];
			if (s[nx][ny]=='X'||~dis[nx][ny]) {
				continue;
			}
			dis[nx][ny]=dis[x][y]+1;
			que[quer++]=pii(nx,ny);
		}
	}
	sort(v,v+sz);
}

pii rats1[M],rats2[M],bomb1[M],bomb2[M];
int szr1,szr2,szb1,szb2;

int main() {
#ifdef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	scanf("%d%d%d",&n,&m,&d);
	pii rat2;
	int i,j,k;
	for(i=0;i<n;i++) scanf("%s",s[i]);
	for(i=0;i<n;i++) {
		for(j=0;j<m;j++) {
			if (s[i][j]=='R') {
				rats.insert(pii(i,j));
			}
		}
	}
	if ((int)rats.size()>290) {
		printf("-1\n");
		return 0;
	}
	bfs(*rats.begin(),RAT,bomb1,szb1);
	for(i=0;i<szb1;i++) {
		#define firstbomb bomb1[i]
//		printf("%d %d\n",firstbomb.first,firstbomb.second);
		bfs(firstbomb,BOMB,rats1,szr1);
		rat2=pii(-1,-1);
		if (!rats.empty()) rat2=*rats.begin();
		if (rat2==pii(-1,-1)) {
			for(j=1;j<n-1;j++) {
				for(k=1;k<m-1;k++) {
					if (pii(j,k)!=firstbomb&&s[j][k]!='X') {
						printf("%d %d %d %d\n",firstbomb.first+1,firstbomb.second+1,j+1,k+1);
						return 0;
					}
				}
			}
		}
		bfs(rat2,RAT,bomb2,szb2);
		for(j=0;j<szb2;j++) {
			#define secondbomb bomb2[j]
//			printf("\t%d %d\n",secondbomb.first,secondbomb.second);
			bfs(secondbomb,BOMB,rats2,szr2);
//			if (firstbomb==pii(4,5)&&secondbomb==pii(3,9)) {
//				for(auto xx:rats) {
//					printf("(%d,%d)",xx.first,xx.second);
//				}
//				printf("\n");
//			}
			if (rats.empty()) {
				printf("%d %d %d %d\n",firstbomb.first+1,firstbomb.second+1,secondbomb.first+1,secondbomb.second+1);
				return 0;
			}
			for(k=0;k<szr2;k++) rats.insert(rats2[k]);
		}
		for(j=0;j<szr1;j++) rats.insert(rats1[j]);
	}
	printf("-1\n");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

#define RAT 0
#define BOMB 1
const int N=1005,M=305;
char s[N][N];
set<pii> rats;
pii now,rat1,rat2,rats1[M],rats2[M],bomb1[M],bomb2[M],que[M];
int n,m,d,szr1,szr2,szb1,szb2,i,j,k,sx,sy,x,y,nx,ny,dir,quel,quer,dis[N][N];

const int dx[]={-1,0,0,1};
const int dy[]={0,-1,1,0};

void bfs(pii st,bool br,pii *v,int &sz) {
	memset(dis,-1,sizeof(dis));
	sz=0;
	quel=quer=0;
	sx=st.first,sy=st.second;
	dis[sx][sy]=0;
	que[quer++]=pii(sx,sy);
	while (quel<quer) {
		now=que[quel++];
		x=now.first,y=now.second;
		if (br!=BOMB||rats.count(pii(x,y))) {
			v[sz++]=pii(x,y);
			if (br==BOMB) rats.erase(rats.find(pii(x,y)));
		}
		if (dis[x][y]==d) continue;
		for(dir=0;dir<4;dir++) {
			nx=x+dx[dir],ny=y+dy[dir];
			if (s[nx][ny]=='X'||~dis[nx][ny]) {
				continue;
			}
			dis[nx][ny]=dis[x][y]+1;
			que[quer++]=pii(nx,ny);
		}
	}
	sort(v,v+sz);
}

int main() {
#ifdef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	scanf("%d%d%d",&n,&m,&d);
	for(i=0;i<n;i++) scanf("%s",s[i]);
	for(i=0;i<n;i++) for(j=0;j<m;j++) if (s[i][j]=='R') rats.insert(pii(i,j));
	rat1=*rats.begin();
	bfs(rat1,RAT,bomb1,szb1);
	for(i=0;i<szb1;i++) {
		bfs(bomb1[i],BOMB,rats1,szr1);
		rat2=pii(-1,-1);
		if (!rats.empty()) rat2=*rats.begin();
		if (rat2==pii(-1,-1)) for(j=1;j<n-1;j++) for(k=1;k<m-1;k++)
			if (s[j][k]!='X'&&bomb1[i].first!=j&&bomb1[i].second!=k) {
				printf("%d %d %d %d\n",bomb1[i].first+1,bomb1[i].second+1,j+1,k+1);
				return 0;
			}
		bfs(rat2,RAT,bomb2,szb2);
		for(j=0;j<szb2;j++) {
			bfs(bomb2[j],BOMB,rats2,szr2);
			if (rats.empty()) {
				printf("%d %d %d %d\n",bomb1[i].first+1,bomb1[i].second+1,bomb2[j].first+1,bomb2[j].second+1);
				return 0;
			}
			for(k=0;k<szr2;k++) rats.insert(rats2[k]);
		}
		for(j=0;j<szr1;j++) rats.insert(rats1[j]);
	}
	printf("-1\n");
	return 0;
}


#include <set>
#include <map>
#include <queue>
#include <deque>
#include <cstdio>
#include <string>
#include <vector>
#include <math.h>
#include <time.h>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <stdio.h>
#include <iomanip>
#include <conio.h>
#include <iostream>
#include <algorithm>
#define max(a,b) (b<a ? a : b)
#define min(a,b) (a<b ? a : b)
#define FAST() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
int dx[]={0,0,-1,1},dy[]={-1,1,0,0};
struct point {
	int x,y;
	point(int X=0,int Y=0) {
		x=X,y=Y;
	}
	~point() {
	}
};
int n,m,d;
char c[1005][1005];
vector<point> rats;
int beat[1005][1005];
vector<point> get_neighbour(int sx,int sy,int val=0) {
	queue<int> q;
	vector<point> v;
	q.push(sx);q.push(sy);q.push(0);
	while (!q.empty()) {
		int x = q.front();q.pop();
		int y = q.front();q.pop();
		beat[x][y]+=val;
		v.push_back(point(x,y));
		int dis = q.front();q.pop();
		if (dis+1 > d) break;
		for (int i = 0;i < 4;i++) {
			int nx = x+dx[i],ny=y+dy[i];
			if (nx>0 && ny>0 && nx<=n && ny<=m && c[nx][ny]!='X') {
				q.push(nx);q.push(ny);q.push(dis+1);
			}
		}
	}
	return v;
}
int main() {
	FAST();
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin >> n >> m >> d;
	for (int i = 1;i <= n;i++)
		for (int j = 1;j <= m;j++) {
			cin >> c[i][j];
			if (c[i][j]=='R')
				rats.push_back(point(i,j));
		}
	if ((int)rats.size() > 300) {
		cout << -1 << endl;
		return 0;
	}
	int x = rats[0].x,y = rats[0].y;
	vector<point> v = get_neighbour(x,y);
	for (int i = 0;i < (int)v.size();i++) {
		int sx = v[i].x,sy=v[i].y;
		vector<point> v1 = get_neighbour(sx,sy);
		for (int k = 0;k < (int)v1.size();k++)
			beat[v1[k].x][v1[k].y]++;
		int s;
		for (s = 0;s < (int)rats.size();s++)
			if (!beat[rats[s].x][rats[s].y]) break;
		if (s == (int)rats.size()) {
			for (int j = 1;j <= n;j++) for (int k = 1;k <= m;k++)
				if (c[j][k]!='X' && !(j==sx && k==sy)) {
					cout << x << " " << y << " " << j << " " << k << endl;
					return 0;
				}
		}
		x = rats[s].x,y = rats[s].y;
		vector <point> v2 = get_neighbour(x,y);
		for (int j = 0;j < (int)v2.size();j++) {
			int xx = v2[j].x,yy = v2[j].y;
			get_neighbour(xx,yy,1);
			bool f = true;
			for (int k = 0;k < (int)rats.size();k++)
				if (!beat[rats[k].x][rats[k].y]) f=false;
			if (f) {
				cout << xx << " " << yy << " " << sx << " " << sy << endl;
				return 0;
			}
			get_neighbour(xx,yy,-1);
		}
		for (int k = 0;k < (int)v1.size();k++)
			beat[v1[k].x][v1[k].y]--;
	}
	cout << -1 << endl;
	return 0;
}


#pragma -O2

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct PAIR {
	int first,second;
	PAIR(int x=0, int y=0) {
		first=x;
		second=y;
	}
	bool operator == (const PAIR &xx) const{
		return first==xx.first && second==xx.second;
	}
	bool operator != (const PAIR &xx) const{
		return first!=xx.first || second!=xx.second;
	}
	void operator = (const PAIR &xx){
		first=xx.first;
		second=xx.second;
	}
	bool operator < (const PAIR &xx) const {
		if (first!=xx.first) return first<xx.first;
		return second<xx.second;
	}
};
typedef PAIR pii;

#define RAT 0
#define BOMB 1
const int N=1005,M=305;
int n,m,d;
char s[N][N];
int dis[N][N];

const int dx[]={-1,1,0,0};
const int dy[]={0,0,-1,1};

pii que[N];
int quel,quer;

set<pii> rats;

void bfs(pii st,bool br,pii *v,int &sz) {
	memset(dis,-1,sizeof(dis));
	sz=0;
	quel=quer=0;
	register int sx=st.first,sy=st.second;
	dis[sx][sy]=0;
	que[quer++]=pii(sx,sy);
	while (quel<quer) {
		pii now=que[quel++];
		register int x=now.first,y=now.second;
		if (br==BOMB) {
			if (s[x][y]=='R') {
				if (rats.count(pii(x,y))) v[sz++]=pii(x,y);
				rats.erase(pii(x,y));
			}
		} else {
			v[sz++]=pii(x,y);
		}
		for(int dir=0;dir<4;dir++) {
			register int nx=x+dx[dir],ny=y+dy[dir];
			if (s[nx][ny]=='X'||~dis[nx][ny]) {
				continue;
			}
			dis[nx][ny]=dis[x][y]+1;
			if (dis[nx][ny]>d) {
				return;
			}
			que[quer++]=pii(nx,ny);
		}
	}
}

pii rats1[M],rats2[M],bomb1[M],bomb2[M];
int szr1,szr2,szb1,szb2;

inline void printans(pii a,pii b) {
	printf("%d %d %d %d\n",a.first+1,a.second+1,b.first+1,b.second+1);
}

int main() {
#ifdef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	scanf("%d%d%d",&n,&m,&d);
	for(int i=0;i<n;i++) scanf("%s",s[i]);
	for(int i=0;i<n;i++) {
		for(int j=0;j<m;j++) {
			if (s[i][j]=='R') {
				rats.insert(pii(i,j));
			}
		}
	}
	if ((int)rats.size()>290) {
		printf("-1\n");
		return 0;
	}
	bfs(*rats.begin(),RAT,bomb1,szb1);
	for(int i=0;i<szb1;i++) {
		pii firstbomb=bomb1[i];
//		printf("%d %d\n",firstbomb.first,firstbomb.second);
		bfs(firstbomb,BOMB,rats1,szr1);
		pii rat2(-1,-1);
		if (!rats.empty()) rat2=*rats.begin();
		if (rat2==pii(-1,-1)) {
			pii secondbomb(-1,-1);
			for(int i=1;i<n-1;i++) {
				for(int j=1;j<m-1;j++) {
					if (pii(i,j)!=firstbomb&&s[i][j]!='X') {
						secondbomb=pii(i,j);
						break;
					}
				}
				if (secondbomb!=pii(-1,-1)) {
					break;
				}
			}
			printans(firstbomb,secondbomb);
			return 0;
		}
		bfs(rat2,RAT,bomb2,szb2);
		for(int j=0;j<szb2;j++) {
			pii secondbomb=bomb2[j];
//			printf("\t%d %d\n",secondbomb.first,secondbomb.second);
			bfs(secondbomb,BOMB,rats2,szr2);
			if (rats.empty()) {
				printans(firstbomb,secondbomb);
				return 0;
			}
			for(int k=0;k<szr2;k++) if (s[rats2[k].first][rats2[k].second]=='R') rats.insert(rats2[k]);
		}
		for(int j=0;j<szr1;j++) if (s[rats1[j].first][rats1[j].second]=='R') rats.insert(rats1[j]);
	}
	printf("-1\n");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

#define RAT 0
#define BOMB 1
const int N=1005,M=305;
int n,m,d;
char s[N][N];
int dis[N][N];

const int dx[]={-1,0,0,1};
const int dy[]={0,-1,1,0};

pii que[N];
int quel,quer;

set<pii> rats;

void bfs(pii st,bool br,pii *v,int &sz) {
	memset(dis,-1,sizeof(dis));
	sz=0;
	quel=quer=0;
	int sx=st.first,sy=st.second,x,y,nx,ny,dir;
	dis[sx][sy]=0;
	que[quer++]=pii(sx,sy);
	while (quel<quer) {
		pii now=que[quel++];
		x=now.first,y=now.second;
		if (br!=BOMB||rats.count(pii(x,y))) {
			v[sz++]=pii(x,y);
			if (br==BOMB) rats.erase(pii(x,y));
		}
		if (dis[x][y]==d) continue;
		for(dir=0;dir<4;dir++) {
			nx=x+dx[dir],ny=y+dy[dir];
			if (s[nx][ny]=='X'||~dis[nx][ny]) {
				continue;
			}
			dis[nx][ny]=dis[x][y]+1;
			que[quer++]=pii(nx,ny);
		}
	}
	sort(v,v+sz);
}

pii rats1[M],rats2[M],bomb1[M],bomb2[M];
int szr1,szr2,szb1,szb2;

int main() {
#ifdef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	scanf("%d%d%d",&n,&m,&d);
	pii rat2;
	int i,j,k;
	for(i=0;i<n;i++) scanf("%s",s[i]);
	for(i=0;i<n;i++) {
		for(j=0;j<m;j++) {
			if (s[i][j]=='R') {
				rats.insert(pii(i,j));
			}
		}
	}
	if ((int)rats.size()>290) {
		printf("-1\n");
		return 0;
	}
	bfs(*rats.begin(),RAT,bomb1,szb1);
	for(i=0;i<szb1;i++) {
		#define firstbomb bomb1[i]
//		printf("%d %d\n",firstbomb.first,firstbomb.second);
		bfs(firstbomb,BOMB,rats1,szr1);
		rat2=pii(-1,-1);
		if (!rats.empty()) rat2=*rats.begin();
		if (rat2==pii(-1,-1)) {
			for(j=1;j<n-1;j++) {
				for(k=1;k<m-1;k++) {
					if (pii(j,k)!=firstbomb&&s[j][k]!='X') {
						printf("%d %d %d %d\n",firstbomb.first+1,firstbomb.second+1,j+1,k+1);
						return 0;
					}
				}
			}
		}
		bfs(rat2,RAT,bomb2,szb2);
		for(j=0;j<szb2;j++) {
			#define secondbomb bomb2[j]
//			printf("\t%d %d\n",secondbomb.first,secondbomb.second);
			bfs(secondbomb,BOMB,rats2,szr2);
//			if (firstbomb==pii(4,5)&&secondbomb==pii(3,9)) {
//				for(auto xx:rats) {
//					printf("(%d,%d)",xx.first,xx.second);
//				}
//				printf("\n");
//			}
			if (rats.empty()) {
				printf("%d %d %d %d\n",firstbomb.first+1,firstbomb.second+1,secondbomb.first+1,secondbomb.second+1);
				return 0;
			}
			for(k=0;k<szr2;k++) rats.insert(rats2[k]);
		}
		for(j=0;j<szr1;j++) rats.insert(rats1[j]);
	}
	printf("-1\n");
	return 0;
}


#include <set>
#include <map>
#include <queue>
#include <deque>
#include <cstdio>
#include <string>
#include <vector>
#include <math.h>
#include <time.h>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <stdio.h>
#include <iomanip>
#include <conio.h>
#include <iostream>
#include <algorithm>
#define max(a,b) (b<a ? a : b)
#define min(a,b) (a<b ? a : b)
#define FAST() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
int dx[]={0,0,-1,1},dy[]={-1,1,0,0};
struct point {
	int x,y;
	point(int X=0,int Y=0) {
		x=X,y=Y;
	}
	~point() {
	}
};
int n,m,d;
char c[1005][1005];
vector<point> rats;
int beat[1005][1005];
vector<point> get_neighbour(int sx,int sy,int val=0) {
	queue<int> q;
	vector<point> v;
	q.push(sx);q.push(sy);q.push(0);
	while (!q.empty()) {
		int x = q.front();q.pop();
		int y = q.front();q.pop();
		beat[x][y]+=val;
		v.push_back(point(x,y));
		int dis = q.front();q.pop();
		if (dis+1 > d) break;
		for (int i = 0;i < 4;i++) {
			int nx = x+dx[i],ny=y+dy[i];
			if (nx>0 && ny>0 && nx<=n && ny<=m && c[nx][ny]!='X') {
				q.push(nx);q.push(ny);q.push(dis+1);
			}
		}
	}
	return v;
}
int main() {
	FAST();
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin >> n >> m >> d;
	for (int i = 1;i <= n;i++)
		for (int j = 1;j <= m;j++) {
			cin >> c[i][j];
			if (c[i][j]=='R')
				rats.push_back(point(i,j));
		}
	if ((int)rats.size() > 300) {
		cout << -1 << endl;
		return 0;
	}
	int x = rats[0].x,y = rats[0].y;
	vector<point> v = get_neighbour(x,y);
	for (int i = 0;i < (int)v.size();i++) {
		int sx = v[i].x,sy=v[i].y;
		vector<point> v1 = get_neighbour(sx,sy);
		for (int k = 0;k < (int)v1.size();k++)
			beat[v1[k].x][v1[k].y]++;
		int s;
		for (s = 0;s < (int)rats.size();s++)
			if (!beat[rats[s].x][rats[s].y]) break;
		if (s == (int)rats.size()) {
			for (int j = 1;j <= n;j++) for (int k = 1;k <= m;k++)
				if (c[j][k]!='X' && !(j==x && k==y)) {
					cout << x << " " << y << " " << j << " " << k << endl;
					return 0;
				}
		}
		x = rats[s].x,y = rats[s].y;
		vector <point> v2 = get_neighbour(x,y);
		for (int j = 0;j < (int)v2.size();j++) {
			int xx = v2[j].x,yy = v2[j].y;
			get_neighbour(xx,yy,1);
			bool f = true;
			for (int k = 0;k < (int)rats.size();k++)
				if (!beat[rats[k].x][rats[k].y]) f=false;
			if (f) {
				cout << x << " " << y << " " << sx << " " << sy << endl;
				return 0;
			}
			get_neighbour(x,y,-1);
		}
	}
	cout << -1 << endl;
	return 0;
}


#include <set>
#include <map>
#include <queue>
#include <deque>
#include <cstdio>
#include <string>
#include <vector>
#include <math.h>
#include <time.h>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <stdio.h>
#include <iomanip>
#include <conio.h>
#include <iostream>
#include <algorithm>
#define max(a,b) (b<a ? a : b)
#define min(a,b) (a<b ? a : b)
#define FAST() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
int dx[]={0,0,-1,1},dy[]={-1,1,0,0};
struct point {
	int x,y;
	point(int X=0,int Y=0) {
		x=X,y=Y;
	}
	~point() {
	}
};
int n,m,d;
char c[1005][1005];
vector<point> rats;
int beat[1005][1005];
vector<point> get_neighbour(int sx,int sy,int val=0) {
	queue<int> q;
	vector<point> v;
	q.push(sx);q.push(sy);q.push(0);
	while (!q.empty()) {
		int x = q.front();q.pop();
		int y = q.front();q.pop();
		beat[x][y]+=val;
		v.push_back(point(x,y));
		int dis = q.front();q.pop();
		if (dis > d) break;
		for (int i = 0;i < 4;i++) {
			int nx = x+dx[i],ny=y+dy[i];
			if (nx>0 && ny>0 && nx<=n && ny<=m && c[nx][ny]!='X') {
				q.push(nx);q.push(ny);q.push(dis+1);
			}
		}
	}
	return v;
}
int main() {
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	scanf("%d%d%d", &n, &m, &d);
	for (int i = 1;i <= n;i++) {
		scanf("%s", c[i] + 1);
		for (int j = 1;j <= m;j++)
			if (c[i][j]=='R') rats.push_back(point(i,j));
	}
	if ((int)rats.size() > 300) {
		printf("-1");
		return 0;
	}
	int x = rats[0].x,y = rats[0].y;
	vector<point> v = get_neighbour(x,y);
	for (int i = 0;i < (int)v.size();i++) {
		int sx = v[i].x,sy=v[i].y;
//		cout << sx << " " << sy << endl;
		vector<point> v1 = get_neighbour(sx,sy);
		for (int k = 0;k < (int)v1.size();k++)
			beat[v1[k].x][v1[k].y]++;
		int s;
		for (s = 0;s < (int)rats.size();s++)
			if (!beat[rats[s].x][rats[s].y]) break;
		if (s == (int)rats.size()) {
			for (int j = 1;j <= n;j++) for (int k = 1;k <= m;k++)
				if (c[j][k]!='X' && !(j==sx && k==sy)) {
					printf("%d %d %d %d", x, y, j, k);
					return 0;
				}
		}
		x = rats[s].x,y = rats[s].y;
		vector <point> v2 = get_neighbour(x,y);
		for (int j = 0;j < (int)v2.size();j++) {
			int xx = v2[j].x,yy = v2[j].y;
			get_neighbour(xx,yy,1);
			bool f = true;
			for (int k = 0;k < (int)rats.size();k++)
				if (!beat[rats[k].x][rats[k].y]) f=false;
			if (f) {
				printf("%d %d %d %d", xx, yy, sx, sy);
				return 0;
			}
			get_neighbour(xx,yy,-1);
		}
		for (int k = 0;k < (int)v1.size();k++)
			beat[v1[k].x][v1[k].y]--;
	}
	printf("-1");
	return 0;
}


#include <set>
#include <map>
#include <queue>
#include <deque>
#include <cstdio>
#include <string>
#include <vector>
#include <math.h>
#include <time.h>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <stdio.h>
#include <iomanip>
#include <conio.h>
#include <iostream>
#include <algorithm>
#define max(a,b) (b<a ? a : b)
#define min(a,b) (a<b ? a : b)
#define FAST() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
int dx[]={0,0,-1,1},dy[]={-1,1,0,0};
struct point {
	int x,y;
	point(int X=0,int Y=0) {
		x=X,y=Y;
	}
	~point() {
	}
};
int n,m,d;
char c[1005][1005];
vector<point> rats;
int beat[1005][1005];
vector<point> get_neighbour(int sx,int sy,int val=0) {
	queue<int> q;
	vector<point> v;
	q.push(sx);q.push(sy);q.push(0);
	while (!q.empty()) {
		int x = q.front();q.pop();
		int y = q.front();q.pop();
		beat[x][y]+=val;
		v.push_back(point(x,y));
		int dis = q.front();q.pop();
		if (dis > d) break;
		for (int i = 0;i < 4;i++) {
			int nx = x+dx[i],ny=y+dy[i];
			if (nx>0 && ny>0 && nx<=n && ny<=m && c[nx][ny]!='X') {
				q.push(nx);q.push(ny);q.push(dis+1);
			}
		}
	}
	return v;
}
int main() {
	FAST();
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin >> n >> m >> d;
	for (int i = 1;i <= n;i++)
		for (int j = 1;j <= m;j++) {
			cin >> c[i][j];
			if (c[i][j]=='R')
				rats.push_back(point(i,j));
		}
	if ((int)rats.size() > 300) {
		cout << -1 << endl;
		return 0;
	}
	int x = rats[0].x,y = rats[0].y;
	vector<point> v = get_neighbour(x,y);
	for (int i = 0;i < (int)v.size();i++) {
		int sx = v[i].x,sy=v[i].y;
//		cout << sx << " " << sy << endl;
		vector<point> v1 = get_neighbour(sx,sy);
		for (int k = 0;k < (int)v1.size();k++)
			beat[v1[k].x][v1[k].y]++;
		int s;
		for (s = 0;s < (int)rats.size();s++)
			if (!beat[rats[s].x][rats[s].y]) break;
		if (s == (int)rats.size()) {
			for (int j = 1;j <= n;j++) for (int k = 1;k <= m;k++)
				if (c[j][k]!='X' && !(j==sx && k==sy)) {
					cout << x << " " << y << " " << j << " " << k << endl;
					return 0;
				}
		}
		x = rats[s].x,y = rats[s].y;
		vector <point> v2 = get_neighbour(x,y);
		for (int j = 0;j < (int)v2.size();j++) {
			int xx = v2[j].x,yy = v2[j].y;
			get_neighbour(xx,yy,1);
			bool f = true;
			for (int k = 0;k < (int)rats.size();k++)
				if (!beat[rats[k].x][rats[k].y]) f=false;
			if (f) {
				cout << xx << " " << yy << " " << sx << " " << sy << endl;
				return 0;
			}
			get_neighbour(xx,yy,-1);
		}
		for (int k = 0;k < (int)v1.size();k++)
			beat[v1[k].x][v1[k].y]--;
	}
	cout << -1 << endl;
	return 0;
}


#include <set>
#include <map>
#include <queue>
#include <deque>
#include <cstdio>
#include <string>
#include <vector>
#include <math.h>
#include <time.h>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <stdio.h>
#include <iomanip>
#include <conio.h>
#include <iostream>
#include <algorithm>
#define max(a,b) (b<a ? a : b)
#define min(a,b) (a<b ? a : b)
#define FAST() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
int dx[]={0,0,-1,1},dy[]={-1,1,0,0};
struct point {
	int x,y;
	point(int X=0,int Y=0) {
		x=X,y=Y;
	}
	~point() {
	}
};
int n,m,d;
char c[1005][1005];
vector<point> rats;
int beat[1005][1005];
vector<point> get_neighbour(int sx,int sy,int val=0) {
	queue<int> q;
	vector<point> v;
	q.push(sx);q.push(sy);q.push(0);
	while (!q.empty()) {
		int x = q.front();q.pop();
		int y = q.front();q.pop();
		beat[x][y]+=val;
		v.push_back(point(x,y));
		int dis = q.front();q.pop();
		if (dis+1 > d) break;
		for (int i = 0;i < 4;i++) {
			int nx = x+dx[i],ny=y+dy[i];
			if (nx>0 && ny>0 && nx<=n && ny<=m && c[nx][ny]!='X') {
				q.push(nx);q.push(ny);q.push(dis+1);
			}
		}
	}
	return v;
}
int main() {
	FAST();
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin >> n >> m >> d;
	for (int i = 1;i <= n;i++)
		for (int j = 1;j <= m;j++) {
			cin >> c[i][j];
			if (c[i][j]=='R')
				rats.push_back(point(i,j));
		}
	if ((int)rats.size() > 300) {
		cout << -1 << endl;
		return 0;
	}
	int x = rats[0].x,y = rats[0].y;
	vector<point> v = get_neighbour(x,y);
	for (int i = 0;i < (int)v.size();i++) {
		int sx = v[i].x,sy=v[i].y;
		vector<point> v1 = get_neighbour(sx,sy);
		for (int k = 0;k < (int)v1.size();k++)
			beat[v1[k].x][v1[k].y]++;
		int s;
		for (s = 0;s < (int)rats.size();s++)
			if (!beat[rats[s].x][rats[s].y]) break;
		if (s == (int)rats.size()) {
			for (int j = 1;j <= n;j++) for (int k = 1;k <= m;k++)
				if (c[j][k]!='X' && !(j==x && k==y)) {
					cout << x << " " << y << " " << j << " " << k << endl;
					return 0;
				}
		}
		x = rats[s].x,y = rats[s].y;
		vector <point> v2 = get_neighbour(x,y);
		for (int j = 0;j < (int)v2.size();j++) {
			int xx = v2[j].x,yy = v2[j].y;
			get_neighbour(xx,yy,1);
			bool f = true;
			for (int k = 0;k < (int)rats.size();k++)
				if (!beat[rats[k].x][rats[k].y]) f=false;
			if (f) {
				cout << x << " " << y << " " << sx << " " << sy << endl;
				return 0;
			}
			get_neighbour(xx,yy,-1);
		}
	}
	cout << -1 << endl;
	return 0;
}


#include <set>
#include <map>
#include <queue>
#include <deque>
#include <cstdio>
#include <string>
#include <vector>
#include <math.h>
#include <time.h>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <stdio.h>
#include <iomanip>
#include <conio.h>
#include <iostream>
#include <algorithm>
#define max(a,b) (b<a ? a : b)
#define min(a,b) (a<b ? a : b)
#define FAST() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
int dx[]={0,0,-1,1},dy[]={-1,1,0,0};
struct point {
	int x,y;
	point(int X=0,int Y=0) {
		x=X,y=Y;
	}
	~point() {
	}
};
int n,m,d;
char c[1005][1005];
vector<point> rats;
int beat[1005][1005];
vector<point> get_neighbour(int sx,int sy,int val=0) {
	queue<int> q;
	vector<point> v;
	q.push(sx);q.push(sy);q.push(0);
	while (!q.empty()) {
		int x = q.front();q.pop();
		int y = q.front();q.pop();
		beat[x][y]+=val;
		v.push_back(point(x,y));
		int dis = q.front();q.pop();
		if (dis > d) break;
		for (int i = 0;i < 4;i++) {
			int nx = x+dx[i],ny=y+dy[i];
			if (nx>0 && ny>0 && nx<=n && ny<=m && c[nx][ny]!='X') {
				q.push(nx);q.push(ny);q.push(dis+1);
			}
		}
	}
	return v;
}
int main() {
	FAST();
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin >> n >> m >> d;
	for (int i = 1;i <= n;i++)
		for (int j = 1;j <= m;j++) {
			scanf("%c", &c[i][j]);
			if (c[i][j]=='R')
				rats.push_back(point(i,j));
		}
	if ((int)rats.size() > 300) {
		cout << -1 << endl;
		return 0;
	}
	int x = rats[0].x,y = rats[0].y;
	vector<point> v = get_neighbour(x,y);
	for (int i = 0;i < (int)v.size();i++) {
		int sx = v[i].x,sy=v[i].y;
//		cout << sx << " " << sy << endl;
		vector<point> v1 = get_neighbour(sx,sy);
		for (int k = 0;k < (int)v1.size();k++)
			beat[v1[k].x][v1[k].y]++;
		int s;
		for (s = 0;s < (int)rats.size();s++)
			if (!beat[rats[s].x][rats[s].y]) break;
		if (s == (int)rats.size()) {
			for (int j = 1;j <= n;j++) for (int k = 1;k <= m;k++)
				if (c[j][k]!='X' && !(j==sx && k==sy)) {
					cout << x << " " << y << " " << j << " " << k << endl;
					return 0;
				}
		}
		x = rats[s].x,y = rats[s].y;
		vector <point> v2 = get_neighbour(x,y);
		for (int j = 0;j < (int)v2.size();j++) {
			int xx = v2[j].x,yy = v2[j].y;
			get_neighbour(xx,yy,1);
			bool f = true;
			for (int k = 0;k < (int)rats.size();k++)
				if (!beat[rats[k].x][rats[k].y]) f=false;
			if (f) {
				cout << xx << " " << yy << " " << sx << " " << sy << endl;
				return 0;
			}
			get_neighbour(xx,yy,-1);
		}
		for (int k = 0;k < (int)v1.size();k++)
			beat[v1[k].x][v1[k].y]--;
	}
	cout << -1 << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

#define RAT 0
#define BOMB 1
const int N=1005,M=305;
int n,m,d;
char s[N][N];
int dis[N][N];

const int dx[]={-1,0,0,1};
const int dy[]={0,-1,1,0};

pii que[N];
int quel,quer;

set<pii> rats;

void bfs(pii st,bool br,pii *v,int &sz) {
	memset(dis,-1,sizeof(dis));
	sz=0;
	quel=quer=0;
	int sx=st.first,sy=st.second,x,y,nx,ny,dir;
	dis[sx][sy]=0;
	que[quer++]=pii(sx,sy);
	while (quel<quer) {
		pii now=que[quel++];
		x=now.first,y=now.second;
		if (br!=BOMB||rats.count(pii(x,y))) {
			v[sz++]=pii(x,y);
			if (br==BOMB) rats.erase(pii(x,y));
		}
		if (dis[x][y]==d) continue;
		for(dir=0;dir<4;dir++) {
			nx=x+dx[dir],ny=y+dy[dir];
			if (s[nx][ny]=='X'||~dis[nx][ny]) {
				continue;
			}
			dis[nx][ny]=dis[x][y]+1;
			que[quer++]=pii(nx,ny);
		}
	}
	sort(v,v+sz);
}

pii rats1[M],rats2[M],bomb1[M],bomb2[M];
int szr1,szr2,szb1,szb2;

int main() {
#ifdef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	scanf("%d%d%d",&n,&m,&d);
	pii rat1,rat2;
	int i,j,k;
	for(i=0;i<n;i++) scanf("%s",s[i]);
	for(i=0;i<n;i++) {
		for(j=0;j<m;j++) {
			if (s[i][j]=='R') {
				rats.insert(pii(i,j));
			}
		}
	}
	if ((int)rats.size()>290) {
		printf("-1\n");
		return 0;
	}
	rat1=*rats.begin();
	bfs(rat1,RAT,bomb1,szb1);
	for(i=0;i<szb1;i++) {
//		printf("%d %d\n",bomb1[i].first,bomb1[i].second);
		bfs(bomb1[i],BOMB,rats1,szr1);
		rat2=pii(-1,-1);
		if (!rats.empty()) rat2=*rats.begin();
		if (rat2==pii(-1,-1)) {
			for(j=1;j<n-1;j++) {
				for(k=1;k<m-1;k++) {
					if (pii(j,k)!=bomb1[i]&&s[j][k]!='X') {
						printf("%d %d %d %d\n",bomb1[i].first+1,bomb1[i].second+1,j+1,k+1);
						return 0;
					}
				}
			}
		}
		bfs(rat2,RAT,bomb2,szb2);
		for(j=0;j<szb2;j++) {
//			printf("\t%d %d\n",bomb2[j].first,bomb2[j].second);
			bfs(bomb2[j],BOMB,rats2,szr2);
//			if (bomb1[i]==pii(4,5)&&bomb2[j]==pii(3,9)) {
//				for(auto xx:rats) {
//					printf("(%d,%d)",xx.first,xx.second);
//				}
//				printf("\n");
//			}
			if (rats.empty()) {
				printf("%d %d %d %d\n",bomb1[i].first+1,bomb1[i].second+1,bomb2[j].first+1,bomb2[j].second+1);
				return 0;
			}
			for(k=0;k<szr2;k++) rats.insert(rats2[k]);
		}
		for(j=0;j<szr1;j++) rats.insert(rats1[j]);
	}
	printf("-1\n");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

#define RAT 0
#define BOMB 1
const int N=1005,M=305;
char s[N][N];
set<pii> rats;
bool vis[N][N];
pair<int,pii> que[M];
pii now,rat1,rat2,rats1[M],rats2[M],bomb1[M],bomb2[M];
int n,m,d,szr1,szr2,szb1,szb2,i,j,k,sx,sy,x,y,nx,ny,dir,quel,quer,dis;

const int dx[]={-1,0,0,1};
const int dy[]={0,-1,1,0};

void bfs(pii st,bool br,pii *v,int &sz) {
	memset(vis,0,sizeof(vis));
	sz=0;
	quel=quer=0;
	sx=st.first,sy=st.second;
	que[quer++]=pair<int,pii>(0,pii(sx,sy));
	while (quel<quer) {
		now=que[quel].second;
		dis=que[quel++].first+1;
		x=now.first,y=now.second;
		if (br!=BOMB||rats.count(pii(x,y))) {
			v[sz++]=pii(x,y);
			if (br==BOMB) rats.erase(rats.find(pii(x,y)));
		}
		if (dis>d) continue;
		for(dir=0;dir<4;dir++) {
			nx=x+dx[dir],ny=y+dy[dir];
			if (s[nx][ny]=='X'||vis[nx][ny]) continue;
			vis[nx][ny]=1;
			que[quer++]=pair<int,pii>(dis,pii(nx,ny));
		}
	}
}

int main() {
#ifdef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	scanf("%d%d%d",&n,&m,&d);
	for(i=0;i<n;i++) scanf("%s",s[i]);
	for(i=0;i<n;i++) for(j=0;j<m;j++) if (s[i][j]=='R') rats.insert(pii(i,j));
	rat1=*rats.begin();
	bfs(rat1,RAT,bomb1,szb1);
	for(i=0;i<szb1;i++) {
		bfs(bomb1[i],BOMB,rats1,szr1);
		rat2=pii(-1,-1);
		if (!rats.empty()) rat2=*rats.begin();
		if (rat2==pii(-1,-1)) for(j=1;j<n-1;j++) for(k=1;k<m-1;k++)
			if (s[j][k]!='X'&&bomb1[i].first!=j&&bomb1[i].second!=k) {
				printf("%d %d %d %d\n",bomb1[i].first+1,bomb1[i].second+1,j+1,k+1);
				return 0;
			}
		bfs(rat2,RAT,bomb2,szb2);
		for(j=0;j<szb2;j++) {
			bfs(bomb2[j],BOMB,rats2,szr2);
			if (rats.empty()) {
				printf("%d %d %d %d\n",bomb1[i].first+1,bomb1[i].second+1,bomb2[j].first+1,bomb2[j].second+1);
				return 0;
			}
			for(k=0;k<szr2;k++) rats.insert(rats2[k]);
		}
		for(j=0;j<szr1;j++) rats.insert(rats1[j]);
	}
	printf("-1\n");
	return 0;
}


#pragma -O2

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct PAIR {
	int first,second;
	PAIR(int x=0, int y=0) {
		first=x;
		second=y;
	}
	bool operator == (const PAIR &xx) const{
		return first==xx.first && second==xx.second;
	}
	bool operator != (const PAIR &xx) const{
		return first!=xx.first || second!=xx.second;
	}
	void operator = (const PAIR &xx){
		first=xx.first;
		second=xx.second;
	}
	bool operator < (const PAIR &xx) const {
		if (first!=xx.first) return first<xx.first;
		return second<xx.second;
	}
};
typedef PAIR pii;

#define RAT 0
#define BOMB 1
const int N=1005,M=305;
int n,m,d;
char s[N][N];
int dis[N][N];

const int dx[]={-1,0,0,1};
const int dy[]={0,-1,1,0};

pii que[N];
int quel,quer;

set<pii> rats;

void bfs(pii st,bool br,pii *v,int &sz) {
	memset(dis,-1,sizeof(dis));
	sz=0;
	quel=quer=0;
	register int sx=st.first,sy=st.second;
	dis[sx][sy]=0;
	que[quer++]=pii(sx,sy);
	while (quel<quer) {
		pii now=que[quel++];
		register int x=now.first,y=now.second;
		if (br==BOMB) {
			if (s[x][y]=='R') {
				if (rats.count(pii(x,y))) {
					v[sz++]=pii(x,y);
					rats.erase(pii(x,y));
				}
			}
		} else {
			v[sz++]=pii(x,y);
		}
		if (dis[x][y]==d) continue;
		for(int dir=0;dir<4;dir++) {
			register int nx=x+dx[dir],ny=y+dy[dir];
			if (s[nx][ny]=='X'||~dis[nx][ny]) {
				continue;
			}
			dis[nx][ny]=dis[x][y]+1;
			que[quer++]=pii(nx,ny);
		}
	}
}

pii rats1[M],rats2[M],bomb1[M],bomb2[M];
int szr1,szr2,szb1,szb2;

inline void printans(pii a,pii b) {
	printf("%d %d %d %d\n",a.first+1,a.second+1,b.first+1,b.second+1);
}

int main() {
#ifdef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	scanf("%d%d%d",&n,&m,&d);
	for(int i=0;i<n;i++) scanf("%s",s[i]);
	for(int i=0;i<n;i++) {
		for(int j=0;j<m;j++) {
			if (s[i][j]=='R') {
				rats.insert(pii(i,j));
			}
		}
	}
	if ((int)rats.size()>290) {
		printf("-1\n");
		return 0;
	}
	bfs(*rats.begin(),RAT,bomb1,szb1);
	for(int i=0;i<szb1;i++) {
		pii firstbomb=bomb1[i];
//		printf("%d %d\n",firstbomb.first,firstbomb.second);
		bfs(firstbomb,BOMB,rats1,szr1);
		pii rat2(-1,-1);
		if (!rats.empty()) rat2=*rats.begin();
		if (rat2==pii(-1,-1)) {
			pii secondbomb(-1,-1);
			for(int i=1;i<n-1;i++) {
				for(int j=1;j<m-1;j++) {
					if (pii(i,j)!=firstbomb&&s[i][j]!='X') {
						secondbomb=pii(i,j);
						break;
					}
				}
				if (secondbomb!=pii(-1,-1)) {
					break;
				}
			}
			printans(firstbomb,secondbomb);
			return 0;
		}
		bfs(rat2,RAT,bomb2,szb2);
		for(int j=0;j<szb2;j++) {
			pii secondbomb=bomb2[j];
//			printf("\t%d %d\n",secondbomb.first,secondbomb.second);
			bfs(secondbomb,BOMB,rats2,szr2);
//			if (firstbomb==pii(4,5)&&secondbomb==pii(3,9)) {
//				for(auto xx:rats) {
//					printf("(%d,%d)",xx.first,xx.second);
//				}
//				printf("\n");
//			}
			if (rats.empty()) {
				printans(firstbomb,secondbomb);
				return 0;
			}
			for(int k=0;k<szr2;k++) if (s[rats2[k].first][rats2[k].second]=='R') rats.insert(rats2[k]);
		}
		for(int j=0;j<szr1;j++) if (s[rats1[j].first][rats1[j].second]=='R') rats.insert(rats1[j]);
	}
	printf("-1\n");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

#define RAT 0
#define BOMB 1
const int N=1005,M=305;
char s[N][N];
set<pii> rats;
pii now,rat1,rat2,rats1[M],rats2[M],bomb1[M],bomb2[M],que[M];
int n,m,d,szr1,szr2,szb1,szb2,i,j,k,sx,sy,x,y,nx,ny,dir,quel,quer,dis[N][N];

const int dx[]={-1,0,0,1};
const int dy[]={0,-1,1,0};

void bfs(pii st,bool br,pii *v,int &sz) {
	memset(dis,-1,sizeof(dis));
	sz=0;
	quel=quer=0;
	sx=st.first,sy=st.second;
	dis[sx][sy]=0;
	que[quer++]=pii(sx,sy);
	while (quel<quer) {
		now=que[quel++];
		x=now.first,y=now.second;
		if (br!=BOMB||rats.count(pii(x,y))) {
			v[sz++]=pii(x,y);
			if (br==BOMB) rats.erase(rats.find(pii(x,y)));
		}
		for(dir=0;dir<4;dir++) {
			nx=x+dx[dir],ny=y+dy[dir];
			if (s[nx][ny]=='X'||~dis[nx][ny]) {
				continue;
			}
			dis[nx][ny]=dis[x][y]+1;
			if (dis[nx][ny]>d) continue;
			que[quer++]=pii(nx,ny);
		}
	}
	sort(v,v+sz);
}

int main() {
#ifdef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	scanf("%d%d%d",&n,&m,&d);
	for(i=0;i<n;i++) scanf("%s",s[i]);
	for(i=0;i<n;i++) for(j=0;j<m;j++) if (s[i][j]=='R') rats.insert(pii(i,j));
	rat1=*rats.begin();
	bfs(rat1,RAT,bomb1,szb1);
	for(i=0;i<szb1;i++) {
		bfs(bomb1[i],BOMB,rats1,szr1);
		rat2=pii(-1,-1);
		if (!rats.empty()) rat2=*rats.begin();
		if (rat2==pii(-1,-1)) for(j=1;j<n-1;j++) for(k=1;k<m-1;k++)
			if (s[j][k]!='X'&&bomb1[i].first!=j&&bomb1[i].second!=k) {
				printf("%d %d %d %d\n",bomb1[i].first+1,bomb1[i].second+1,j+1,k+1);
				return 0;
			}
		bfs(rat2,RAT,bomb2,szb2);
		for(j=0;j<szb2;j++) {
			bfs(bomb2[j],BOMB,rats2,szr2);
			if (rats.empty()) {
				printf("%d %d %d %d\n",bomb1[i].first+1,bomb1[i].second+1,bomb2[j].first+1,bomb2[j].second+1);
				return 0;
			}
			for(k=0;k<szr2;k++) rats.insert(rats2[k]);
		}
		for(j=0;j<szr1;j++) rats.insert(rats1[j]);
	}
	printf("-1\n");
	return 0;
}


#include <set>
#include <map>
#include <queue>
#include <deque>
#include <cstdio>
#include <string>
#include <vector>
#include <math.h>
#include <time.h>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <stdio.h>
#include <iomanip>
#include <conio.h>
#include <iostream>
#include <algorithm>
#define max(a,b) (b<a ? a : b)
#define min(a,b) (a<b ? a : b)
#define FAST() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
int dx[]={0,0,-1,1},dy[]={-1,1,0,0};
struct point {
	int x,y;
	point(int X=0,int Y=0) {
		x=X,y=Y;
	}
	~point() {
	}
};
int n,m,d;
char c[1005][1005];
vector<point> rats;
int beat[1005][1005];
vector<point> get_neighbour(int sx,int sy,int val=0) {
	queue<int> q;
	vector<point> v;
	q.push(sx);q.push(sy);q.push(0);
	while (!q.empty()) {
		int x = q.front();q.pop();
		int y = q.front();q.pop();
		beat[x][y]+=val;
		v.push_back(point(x,y));
		int dis = q.front();q.pop();
		if (dis+1 > d) break;
		for (int i = 0;i < 4;i++) {
			int nx = x+dx[i],ny=y+dy[i];
			if (nx>0 && ny>0 && nx<=n && ny<=m && c[nx][ny]!='X') {
				q.push(nx);q.push(ny);q.push(dis+1);
			}
		}
	}
	return v;
}
int main() {
	FAST();
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin >> n >> m >> d;
	for (int i = 1;i <= n;i++)
		for (int j = 1;j <= m;j++) {
			cin >> c[i][j];
			if (c[i][j]=='R')
				rats.push_back(point(i,j));
		}
	if ((int)rats.size() > 300) {
		cout << -1 << endl;
		return 0;
	}
	int x = rats[0].x,y = rats[0].y;
	vector<point> v = get_neighbour(x,y);
	for (int i = 0;i < (int)v.size();i++) {
		int sx = v[i].x,sy=v[i].y;
		vector<point> v1 = get_neighbour(sx,sy);
		for (int k = 0;k < (int)v1.size();k++)
			beat[v1[k].x][v1[k].y]++;
		int s;
		for (s = 0;s < (int)rats.size();s++)
			if (!beat[rats[s].x][rats[s].y]) break;
		if (s == (int)rats.size()) {
			for (int j = 1;j <= n;j++) for (int k = 1;k <= m;k++)
				if (c[j][k]!='X' && !(j==x && k==y)) {
					cout << x << " " << y << " " << j << " " << k << endl;
					return 0;
				}
		}
		x = rats[s].x,y = rats[s].y;
		vector <point> v2 = get_neighbour(x,y);
		for (int j = 0;j < (int)v2.size();j++) {
			int xx = v2[j].x,yy = v2[j].y;
			get_neighbour(xx,yy,1);
			bool f = true;
			for (int k = 0;k < (int)rats.size();k++)
				if (!beat[rats[k].x][rats[k].y]) f=false;
			if (f) {
				cout << x << " " << y << " " << sx << " " << sy << endl;
				return 0;
			}
			get_neighbour(xx,yy,-1);
		}
		for (int k = 0;k < (int)v1.size();k++)
			beat[v1[k].x][v1[k].y]--;
	}
	cout << -1 << endl;
	return 0;
}


#pragma -O2

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct PAIR {
	int first,second;
	PAIR(int x=0, int y=0) {
		first=x;
		second=y;
	}
	bool operator == (const PAIR &xx) const{
		return first==xx.first && second==xx.second;
	}
	bool operator != (const PAIR &xx) const{
		return first!=xx.first || second!=xx.second;
	}
	void operator = (const PAIR &xx){
		first=xx.first;
		second=xx.second;
	}
	bool operator < (const PAIR &xx) const {
		if (first!=xx.first) return first<xx.first;
		return second<xx.second;
	}
};
typedef PAIR pii;

#define RAT 0
#define BOMB 1
const int N=1005,M=305;
int n,m,d;
char s[N][N];
int dis[N][N];

const int dx[]={-1,0,0,1};
const int dy[]={0,-1,1,0};

pii que[N];
int quel,quer;

set<pii> rats;

void bfs(pii st,bool br,pii *v,int &sz) {
	memset(dis,-1,sizeof(dis));
	sz=0;
	quel=quer=0;
	int sx=st.first,sy=st.second,x,y,nx,ny,dir;
	dis[sx][sy]=0;
	que[quer++]=pii(sx,sy);
	while (quel<quer) {
		pii now=que[quel++];
		x=now.first,y=now.second;
		if (br==BOMB) {
			if (s[x][y]=='R') {
				if (rats.count(pii(x,y))) {
					v[sz++]=pii(x,y);
					rats.erase(pii(x,y));
				}
			}
		} else {
			v[sz++]=pii(x,y);
		}
		if (dis[x][y]==d) continue;
		for(dir=0;dir<4;dir++) {
			nx=x+dx[dir],ny=y+dy[dir];
			if (s[nx][ny]=='X'||~dis[nx][ny]) {
				continue;
			}
			dis[nx][ny]=dis[x][y]+1;
			que[quer++]=pii(nx,ny);
		}
	}
	sort(v,v+sz);
}

pii rats1[M],rats2[M],bomb1[M],bomb2[M];
int szr1,szr2,szb1,szb2;

int main() {
#ifdef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	scanf("%d%d%d",&n,&m,&d);
	pii rat2;
	int i,j,k;
	for(int i=0;i<n;i++) scanf("%s",s[i]);
	for(int i=0;i<n;i++) {
		for(int j=0;j<m;j++) {
			if (s[i][j]=='R') {
				rats.insert(pii(i,j));
			}
		}
	}
	if ((int)rats.size()>290) {
		printf("-1\n");
		return 0;
	}
	bfs(*rats.begin(),RAT,bomb1,szb1);
	for(i=0;i<szb1;i++) {
		#define firstbomb bomb1[i]
//		printf("%d %d\n",firstbomb.first,firstbomb.second);
		bfs(firstbomb,BOMB,rats1,szr1);
		rat2=pii(-1,-1);
		if (!rats.empty()) rat2=*rats.begin();
		if (rat2==pii(-1,-1)) {
			for(j=1;j<n-1;j++) {
				for(k=1;k<m-1;k++) {
					if (pii(j,k)!=firstbomb&&s[j][k]!='X') {
						printf("%d %d %d %d\n",firstbomb.first+1,firstbomb.second+1,i+1,j+1);
						return 0;
					}
				}
			}
		}
		bfs(rat2,RAT,bomb2,szb2);
		for(j=0;j<szb2;j++) {
			#define secondbomb bomb2[j]
//			printf("\t%d %d\n",secondbomb.first,secondbomb.second);
			bfs(secondbomb,BOMB,rats2,szr2);
//			if (firstbomb==pii(4,5)&&secondbomb==pii(3,9)) {
//				for(auto xx:rats) {
//					printf("(%d,%d)",xx.first,xx.second);
//				}
//				printf("\n");
//			}
			if (rats.empty()) {
				printf("%d %d %d %d\n",firstbomb.first+1,firstbomb.second+1,secondbomb.first+1,secondbomb.second+1);
				return 0;
			}
			for(k=0;k<szr2;k++) if (s[rats2[k].first][rats2[k].second]=='R') rats.insert(rats2[k]);
		}
		for(j=0;j<szr1;j++) if (s[rats1[j].first][rats1[j].second]=='R') rats.insert(rats1[j]);
	}
	printf("-1\n");
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

const int MaxN = 1000;
const int MaxM = 1000;

const int MaxD = 8;
const int MaxCD = 2 * MaxD * (MaxD + 1) + 1;
const int MaxRN = MaxCD * 2;

const int ND = 4;
const int DX[] = {-1,  0, 0, 1};
const int DY[] = { 0, -1, 1, 0};

int r_n = 0;
pair<int, int> r[MaxRN];
int rg_l[MaxRN];
pair<int, int> rg[MaxRN][MaxCD];

inline bool isInRG(int p, const pair<int, int> &val)
{
	int idx = lower_bound(rg[p], rg[p] + rg_l[p], val) - rg[p];
	return idx < rg_l[p] && rg[p][idx] == val;
}

int main()
{
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

	int n, m, d;
	static char a[MaxN + 1][MaxM + 2];

	cin >> n >> m >> d;
	for (int i = 1; i <= n; i++)
		scanf("%s", a[i] + 1);

	static int dist[MaxN + 1][MaxM + 1];
	for (int x = 1; x <= n; x++)
		for (int y = 1; y <= m; y++)
			dist[x][y] = -1;

	for (int x = 1; x <= n; x++)
		for (int y = 1; y <= m; y++)
			if (a[x][y] == 'R')
			{
				if (r_n == 2 * d * (d + 1) + 1)
				{
					cout << -1 << endl;
					return 0;
				}
				r[r_n] = make_pair(x, y);

				rg_l[r_n] = 0;
				dist[x][y] = 0, rg[r_n][rg_l[r_n]++] = make_pair(x, y);
				for (int i = 0; i < rg_l[r_n]; i++)
				{
					pair<int, int> v = rg[r_n][i];
					if (dist[v.first][v.second] == d)
						continue;
					for (int d = 0; d < ND; d++)
					{
						pair<int, int> u = make_pair(v.first + DX[d], v.second + DY[d]);
						if (a[u.first][u.second] != 'X' && dist[u.first][u.second] == -1)
							dist[u.first][u.second] = dist[v.first][v.second] + 1, rg[r_n][rg_l[r_n]++] = u;
					}
				}
				for (int i = 0; i < rg_l[r_n]; i++)
					dist[rg[r_n][i].first][rg[r_n][i].second] = -1;
				sort(rg[r_n], rg[r_n] + rg_l[r_n]);
				r_n++;
			}

	for (int i = 0; i < rg_l[0]; i++)
	{
		int p = 1;
		while (p < r_n && isInRG(p, rg[0][i]))
			p++;
		if (p == r_n)
		{
			for (int x = 1; x <= n; x++)
				for (int y = 1; y <= m; y++)
					if (a[x][y] != 'X' && rg[0][i] != make_pair(x, y))
					{
						cout << rg[0][i].first << " " << rg[0][i].second << " " << x << " " << y << endl;
						return 0;
					}
		}
		for (int j = 0; j < rg_l[p]; j++)
		{
			bool ok = true;
			for (int q = p + 1; q < r_n && ok; q++)
				if (!isInRG(q, rg[0][i]) && !isInRG(q, rg[p][j]))
					ok = false;
			if (ok)
			{
				cout << rg[0][i].first << " " << rg[0][i].second << " " << rg[p][j].first << " " << rg[p][j].second << endl;
				return 0;
			}
		}
	}

	cout << -1 << endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

const int MaxN = 1000;
const int MaxM = 1000;

const int MaxD = 8;
const int MaxCD = 2 * MaxD * (MaxD + 1) + 1;
const int MaxRN = MaxCD * 2;

const int ND = 4;
const int DX[] = {-1,  0, 0, 1};
const int DY[] = { 0, -1, 1, 0};

int r_n = 0;
pair<int, int> r[MaxRN];
int rg_l[MaxRN];
pair<int, int> rg[MaxRN][MaxCD];

inline bool isInRG(int p, const pair<int, int> &val)
{
	int idx = lower_bound(rg[p], rg[p] + rg_l[p], val) - rg[p];
	return idx < rg_l[p] && rg[p][idx] == val;
}

int main()
{
	int n, m, d;
	static char a[MaxN + 1][MaxM + 2];

	cin >> n >> m >> d;
	for (int i = 1; i <= n; i++)
		scanf("%s", a[i] + 1);

	static int dist[MaxN + 1][MaxM + 1];
	for (int x = 1; x <= n; x++)
		for (int y = 1; y <= m; y++)
			dist[x][y] = -1;

	for (int x = 1; x <= n; x++)
		for (int y = 1; y <= m; y++)
			if (a[x][y] == 'R')
			{
				if (r_n == d * (d + 1) + 1)
				{
					cout << -1 << endl;
					return 0;
				}
				r[r_n] = make_pair(x, y);

				rg_l[r_n] = 0;
				dist[x][y] = 0, rg[r_n][rg_l[r_n]++] = make_pair(x, y);
				for (int i = 0; i < rg_l[r_n]; i++)
				{
					pair<int, int> v = rg[r_n][i];
					if (dist[v.first][v.second] == d)
						continue;
					for (int d = 0; d < ND; d++)
					{
						pair<int, int> u = make_pair(v.first + DX[d], v.second + DY[d]);
						if (a[u.first][u.second] != 'X' && dist[u.first][u.second] == -1)
							dist[u.first][u.second] = dist[v.first][v.second] + 1, rg[r_n][rg_l[r_n]++] = u;
					}
				}
				for (int i = 0; i < rg_l[r_n]; i++)
					dist[rg[r_n][i].first][rg[r_n][i].second] = -1;
				sort(rg[r_n], rg[r_n] + rg_l[r_n]);
				r_n++;
			}

	for (int i = 0; i < rg_l[0]; i++)
	{
		int p = 1;
		while (p < r_n && isInRG(p, rg[0][i]))
			p++;
		if (p == r_n)
		{
			for (int x = 1; x <= n; x++)
				for (int y = 1; y <= m; y++)
					if (a[x][y] != 'X' && rg[0][i] != make_pair(x, y))
					{
						cout << rg[0][i].first << " " << rg[0][i].second << " " << x << " " << y << endl;
						return 0;
					}
		}

		for (int j = 0; j < rg_l[p]; j++)
		{
			bool ok = true;
			for (int q = p + 1; q < r_n && ok; q++)
				if (!isInRG(q, rg[0][i]) && !isInRG(q, rg[p][j]))
					ok = false;
			if (ok)
			{
				cout << rg[0][i].first << " " << rg[0][i].second << " " << rg[p][j].first << " " << rg[p][j].second << endl;
				return 0;
			}
		}
	}

	cout << -1 << endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

const int MaxN = 1000;
const int MaxM = 1000;

const int MaxD = 8;
const int MaxCD = 2 * MaxD * (MaxD + 1) + 1;
const int MaxRN = MaxCD * 2;

const int ND = 4;
const int DX[] = {-1,  0, 0, 1};
const int DY[] = { 0, -1, 1, 0};

int r_n = 0;
pair<int, int> r[MaxRN];
int rg_l[MaxRN];
pair<int, int> rg[MaxRN][MaxCD];

inline bool isInRG(int p, const pair<int, int> &val)
{
	int idx = lower_bound(rg[p], rg[p] + rg_l[p], val) - rg[p];
	return idx < rg_l[p] && rg[p][idx] == val;
}

int main()
{
	int n, m, d;
	static char a[MaxN + 1][MaxM + 2];

	cin >> n >> m >> d;
	for (int i = 1; i <= n; i++)
		scanf("%s", a[i] + 1);

	static int dist[MaxN + 1][MaxM + 1];
	for (int x = 1; x <= n; x++)
		for (int y = 1; y <= m; y++)
			dist[x][y] = -1;

	for (int x = 1; x <= n; x++)
		for (int y = 1; y <= m; y++)
			if (a[x][y] == 'R')
			{
				if (r_n == d * (d + 1) + 1)
				{
					cout << -1 << endl;
					return 0;
				}
				r[r_n] = make_pair(x, y);

				rg_l[r_n] = 0;
				dist[x][y] = 0, rg[r_n][rg_l[r_n]++] = make_pair(x, y);
				for (int i = 0; i < rg_l[r_n]; i++)
				{
					pair<int, int> v = rg[r_n][i];
					if (dist[v.first][v.second] == d)
						continue;
					for (int d = 0; d < ND; d++)
					{
						pair<int, int> u = make_pair(v.first + DX[d], v.second + DY[d]);
						if (a[u.first][u.second] != 'X' && dist[u.first][u.second] == -1)
							dist[u.first][u.second] = dist[v.first][v.second] + 1, rg[r_n][rg_l[r_n]++] = u;
					}
				}
				for (int i = 0; i < rg_l[r_n]; i++)
					dist[rg[r_n][i].first][rg[r_n][i].second] = -1;
				sort(rg[r_n], rg[r_n] + rg_l[r_n]);
				r_n++;
			}

	for (int i = 0; i < rg_l[0]; i++)
	{
		int p = 1;
		while (p < r_n && isInRG(p, rg[0][i]))
			p++;
		if (p == r_n)
		{
			for (int x = 1; x <= n; x++)
				for (int y = 1; y <= m; y++)
					if (a[x][y] != 'X' && rg[0][i] != make_pair(x, y))
					{
						cout << rg[0][i].first << " " << rg[0][i].second << " " << x << " " << y << endl;
						return 0;
					}
		}

		for (int j = 0; j < rg_l[p]; j++)
		{
			bool ok = true;
			for (int q = p + 1; q < r_n && ok; q++)
				if (!isInRG(q, rg[0][i]) && !isInRG(q, rg[p][j]))
					ok = false;
			if (ok)
			{
				cout << rg[0][i].first << " " << rg[0][i].second << " " << rg[p][j].first << " " << rg[p][j].second << endl;
				return 0;
			}
		}
	}

	cout << -1 << endl;

	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

const int MaxN = 1000;
const int MaxM = 1000;

const int MaxD = 8;
const int MaxCD = 2 * MaxD * (MaxD + 1) + 1;
const int MaxRN = MaxCD * 2;

const int ND = 4;
const int DX[] = {-1,  0, 0, 1};
const int DY[] = { 0, -1, 1, 0};

int r_n = 0;
pair<int, int> r[MaxRN];
int rg_l[MaxRN];
pair<int, int> rg[MaxRN][MaxCD];

inline bool isInRG(int p, const pair<int, int> &val)
{
	int idx = lower_bound(rg[p], rg[p] + rg_l[p], val) - rg[p];
	return idx < rg_l[p] && rg[p][idx] == val;
}

int main()
{
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

	int n, m, d;
	static char a[MaxN + 1][MaxM + 2];

	cin >> n >> m >> d;
	for (int i = 1; i <= n; i++)
		scanf("%s", a[i] + 1);

	static int dist[MaxN + 1][MaxM + 1];
	for (int x = 1; x <= n; x++)
		for (int y = 1; y <= m; y++)
			dist[x][y] = -1;

	for (int x = 1; x <= n; x++)
		for (int y = 1; y <= m; y++)
			if (a[x][y] == 'R')
			{
				if (r_n == (2 * d * (d + 1) + 1) * 2)
				{
					cout << -1 << endl;
					return 0;
				}
				r[r_n] = make_pair(x, y);

				rg_l[r_n] = 0;
				dist[x][y] = 0, rg[r_n][rg_l[r_n]++] = make_pair(x, y);
				for (int i = 0; i < rg_l[r_n]; i++)
				{
					pair<int, int> v = rg[r_n][i];
					if (dist[v.first][v.second] == d)
						continue;
					for (int d = 0; d < ND; d++)
					{
						pair<int, int> u = make_pair(v.first + DX[d], v.second + DY[d]);
						if (a[u.first][u.second] != 'X' && dist[u.first][u.second] == -1)
							dist[u.first][u.second] = dist[v.first][v.second] + 1, rg[r_n][rg_l[r_n]++] = u;
					}
				}
				for (int i = 0; i < rg_l[r_n]; i++)
					dist[rg[r_n][i].first][rg[r_n][i].second] = -1;
				sort(rg[r_n], rg[r_n] + rg_l[r_n]);
				r_n++;
			}

	for (int i = 0; i < rg_l[0]; i++)
	{
		int p = 1;
		while (p < r_n && isInRG(p, rg[0][i]))
			p++;
		if (p == r_n)
		{
			for (int x = 1; x <= n; x++)
				for (int y = 1; y <= m; y++)
					if (a[x][y] != 'X' && rg[0][i] != make_pair(x, y))
					{
						cout << rg[0][i].first << " " << rg[0][i].second << " " << x << " " << y << endl;
						return 0;
					}
		}
		for (int j = 0; j < rg_l[p]; j++)
		{
			bool ok = true;
			for (int q = p + 1; q < r_n && ok; q++)
				if (!isInRG(q, rg[0][i]) && !isInRG(q, rg[p][j]))
					ok = false;
			if (ok)
			{
				cout << rg[0][i].first << " " << rg[0][i].second << " " << rg[p][j].first << " " << rg[p][j].second << endl;
				return 0;
			}
		}
	}

	cout << -1 << endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

const int MaxN = 1000;
const int MaxM = 1000;

const int MaxD = 8;
const int MaxCD = 2 * MaxD * (MaxD + 1) + 1;
const int MaxRN = MaxCD * 2;

const int ND = 4;
const int DX[] = {-1,  0, 0, 1};
const int DY[] = { 0, -1, 1, 0};

int r_n = 0;
pair<int, int> r[MaxRN];
int rg_l[MaxRN];
pair<int, int> rg[MaxRN][MaxCD];

inline bool isInRG(int p, const pair<int, int> &val)
{
	int idx = lower_bound(rg[p], rg[p] + rg_l[p], val) - rg[p];
	return idx < rg_l[p] && rg[p][idx] == val;
}

int main()
{
	int n, m, d;
	static char a[MaxN + 1][MaxM + 2];

	cin >> n >> m >> d;
	for (int i = 1; i <= n; i++)
		scanf("%s", a[i] + 1);

	static int dist[MaxN + 1][MaxM + 1];
	for (int x = 1; x <= n; x++)
		for (int y = 1; y <= m; y++)
			dist[x][y] = -1;

	for (int x = 1; x <= n; x++)
		for (int y = 1; y <= m; y++)
			if (a[x][y] == 'R')
			{
				if (r_n == d * (d + 1) + 1)
				{
					cout << -1 << endl;
					return 0;
				}
				r[r_n] = make_pair(x, y);

				rg_l[r_n] = 0;
				dist[x][y] = 0, rg[r_n][rg_l[r_n]++] = make_pair(x, y);
				for (int i = 0; i < rg_l[r_n]; i++)
				{
					pair<int, int> v = rg[r_n][i];
					if (dist[v.first][v.second] == d)
						continue;
					for (int d = 0; d < ND; d++)
					{
						pair<int, int> u = make_pair(v.first + DX[d], v.second + DY[d]);
						if (a[u.first][u.second] != 'X' && dist[u.first][u.second] == -1)
							dist[u.first][u.second] = dist[v.first][v.second] + 1, rg[r_n][rg_l[r_n]++] = u;
					}
				}
				for (int i = 0; i < rg_l[r_n]; i++)
					dist[rg[r_n][i].first][rg[r_n][i].second] = -1;
				sort(rg[r_n], rg[r_n] + rg_l[r_n]);
				r_n++;
			}

	for (int i = 0; i < rg_l[0]; i++)
	{
		int p = 1;
		while (p < r_n && isInRG(p, rg[0][i]))
			p++;
		if (p == r_n)
		{
			for (int x = 1; x <= n; x++)
				for (int y = 1; y <= m; y++)
					if (a[x][y] != 'X' && rg[0][i] != make_pair(x, y))
					{
						cout << rg[0][i].first << " " << rg[0][i].second << " " << x << " " << y << endl;
						return 0;
					}
		}
		for (int j = 0; j < rg_l[p]; j++)
		{
			bool ok = true;
			for (int q = p + 1; q < r_n && ok; q++)
				if (!isInRG(q, rg[0][i]) && !isInRG(q, rg[p][j]))
					ok = false;
			if (ok)
			{
				cout << rg[0][i].first << " " << rg[0][i].second << " " << rg[p][j].first << " " << rg[p][j].second << endl;
				return 0;
			}
		}
	}

	cout << -1 << endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

const int MaxN = 1000;
const int MaxM = 1000;

const int MaxD = 8;
const int MaxCD = 2 * MaxD * (MaxD + 1) + 1;
const int MaxRN = MaxCD * 2;

const int ND = 4;
const int DX[] = {-1,  0, 0, 1};
const int DY[] = { 0, -1, 1, 0};

int r_n = 0;
pair<int, int> r[MaxRN];
int rg_l[MaxRN];
pair<int, int> rg[MaxRN][MaxCD];

inline bool isInRG(int p, const pair<int, int> &val)
{
	int idx = lower_bound(rg[p], rg[p] + rg_l[p], val) - rg[p];
	return idx < rg_l[p] && rg[p][idx] == val;
}

int main()
{
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

	int n, m, d;
	static char a[MaxN + 1][MaxM + 2];

	cin >> n >> m >> d;
	for (int i = 1; i <= n; i++)
		scanf("%s", a[i] + 1);

	static int dist[MaxN + 1][MaxM + 1];
	for (int x = 1; x <= n; x++)
		for (int y = 1; y <= m; y++)
			dist[x][y] = -1;

	for (int x = 1; x <= n; x++)
		for (int y = 1; y <= m; y++)
			if (a[x][y] == 'R')
			{
				if (r_n == d * (d + 1) + 1)
				{
					cout << -1 << endl;
					return 0;
				}
				r[r_n] = make_pair(x, y);

				rg_l[r_n] = 0;
				dist[x][y] = 0, rg[r_n][rg_l[r_n]++] = make_pair(x, y);
				for (int i = 0; i < rg_l[r_n]; i++)
				{
					pair<int, int> v = rg[r_n][i];
					if (dist[v.first][v.second] == d)
						continue;
					for (int d = 0; d < ND; d++)
					{
						pair<int, int> u = make_pair(v.first + DX[d], v.second + DY[d]);
						if (a[u.first][u.second] != 'X' && dist[u.first][u.second] == -1)
							dist[u.first][u.second] = dist[v.first][v.second] + 1, rg[r_n][rg_l[r_n]++] = u;
					}
				}
				for (int i = 0; i < rg_l[r_n]; i++)
					dist[rg[r_n][i].first][rg[r_n][i].second] = -1;
				sort(rg[r_n], rg[r_n] + rg_l[r_n]);
				r_n++;
			}

	for (int i = 0; i < rg_l[0]; i++)
	{
		int p = 1;
		while (p < r_n && isInRG(p, rg[0][i]))
			p++;
		if (p == r_n)
		{
			for (int x = 1; x <= n; x++)
				for (int y = 1; y <= m; y++)
					if (a[x][y] != 'X' && rg[0][i] != make_pair(x, y))
					{
						cout << rg[0][i].first << " " << rg[0][i].second << " " << x << " " << y << endl;
						return 0;
					}
		}
		for (int j = 0; j < rg_l[p]; j++)
		{
			bool ok = true;
			for (int q = p + 1; q < r_n && ok; q++)
				if (!isInRG(q, rg[0][i]) && !isInRG(q, rg[p][j]))
					ok = false;
			if (ok)
			{
				cout << rg[0][i].first << " " << rg[0][i].second << " " << rg[p][j].first << " " << rg[p][j].second << endl;
				return 0;
			}
		}
	}

	cout << -1 << endl;
	return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 2050
int st,n,m,p,ss,Rat[N][2],s[N][N],li[N][3],sg[N][3];
bool b[N][N],c[N][N],d[N][N];char a[N];int cnt[N][N][2];
const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
inline bool Inspect(int x,int y)
 {return x>0&&y>0&&x<=n&&y<=m;}
void BFS(int x,int y)
 {
    int le=1,ri=1;
    li[1][0]=x;li[1][1]=y;li[1][2]=p;c[x][y]=true;s[x][y]++;
    for (;le<=ri;le++)
     if (li[le][2])
      for (int i=0;i<4;i++)
       {
          int k=li[le][0]+dir[i][0],l=li[le][1]+dir[i][1];
          if (!Inspect(k,l)||c[k][l]||b[k][l]) continue;
          li[++ri][0]=k;li[ri][1]=l;li[ri][2]=li[le][2]-1;
          c[k][l]=true;s[k][l]++;
       }
    for (int i=1;i<=ri;i++) c[li[i][0]][li[i][1]]=false;
 }
inline void Update(int x,int y)
 {
    if (cnt[x][y][1]!=ss)
      cnt[x][y][1]=ss,cnt[x][y][0]=1; else
      cnt[x][y][0]++;
 }
int Solve(int x,int y)
 {
    int le=1,ri=1;
    sg[1][0]=x;sg[1][1]=y;sg[1][2]=p;Update(x,y);d[x][y]=true;
    for (;le<=ri;le++)
     if (sg[le][2])
      for (int i=0;i<4;i++)
       {
          int k=sg[le][0]+dir[i][0],l=sg[le][1]+dir[i][1];
          if (!Inspect(k,l)||d[k][l]||b[k][l]) continue;
          sg[++ri][0]=k;sg[ri][1]=l;sg[ri][2]=sg[le][2]-1;
          d[k][l]=true;Update(k,l);
       }
    for (int i=1;i<=ri;i++)
      d[sg[i][0]][sg[i][1]]=false;
    return ri;
 }
void Check(int x,int y)
 {
    if (s[x][y]==st)
      {
         cout <<x<<' '<<y<<' ';
         for (int i=1;i<=n;i++)
          for (int j=1;j<=m;j++)
           if ((i!=x||j!=y)&&!b[i][j])
            {cout <<i<<' '<<j<<endl;exit(0);}
      }
    int le=1,ri=1;
    li[1][0]=x;li[1][1]=y;li[1][2]=p;c[x][y]=true;
    for (;le<=ri;le++)
     if (li[le][2])
      for (int i=0;i<4;i++)
       {
          int k=li[le][0]+dir[i][0],l=li[le][1]+dir[i][1];
          if (!Inspect(k,l)||c[k][l]||b[k][l]) continue;
          li[++ri][0]=k;li[ri][1]=l;li[ri][2]=li[le][2]-1;
          c[k][l]=true;
       }
    int now=0;ss++;
    for (int i=1;i<=st;i++)
     if (!c[Rat[i][0]][Rat[i][1]])
       now=Solve(Rat[i][0],Rat[i][1]);
    for (int i=1;i<=now;i++)
     if (cnt[sg[i][0]][sg[i][1]][0]+s[x][y]==st)
       {
          cout <<x<<' '<<y<<' '<<sg[i][0]<<' '<<sg[i][1]<<endl;
          exit(0);
       }
    for (int i=1;i<=ri;i++) c[li[i][0]][li[i][1]]=false;
 }
void Work()
 {
    if (st>=327) return;
    for (int i=1;i<=st;i++)
      BFS(Rat[i][0],Rat[i][1]);
    for (int i=1;i<=n;i++)
     for (int j=1;j<=m;j++)
      if (s[i][j]*2>=st) Check(i,j);
 }
int main()
 {
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    cin >>n>>m>>p;
    for (int i=1;i<=n;i++)
     {
        scanf("%s",a+1);
        for (int j=1;j<=m;j++)
         if (a[j]=='R') Rat[++st][0]=i,Rat[st][1]=j; else
         if (a[j]=='X') b[i][j]=true;
     }
    Work();
    puts("-1");
    return 0;
 }


#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 1050
int st,n,m,p,ss,Rat[N][2],s[N][N],li[N][3],sg[N][3];
bool b[N][N],c[N][N],d[N][N];char a[N];int cnt[N][N][2];
const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
inline bool Inspect(int x,int y)
 {return x>0&&y>0&&x<=n&&y<=m;}
void BFS(int x,int y)
 {
    int le=1,ri=1;
    li[1][0]=x;li[1][1]=y;li[1][2]=p;c[x][y]=true;s[x][y]++;
    for (;le<=ri;le++)
     if (li[le][2])
      for (int i=0;i<4;i++)
       {
          int k=li[le][0]+dir[i][0],l=li[le][1]+dir[i][1];
          if (!Inspect(k,l)||c[k][l]||b[k][l]) continue;
          li[++ri][0]=k;li[ri][1]=l;li[ri][2]=li[le][2]-1;
          c[k][l]=true;s[k][l]++;
       }
    for (int i=1;i<=ri;i++) c[li[i][0]][li[i][1]]=false;
 }
inline void Update(int x,int y)
 {
    if (cnt[x][y][1]!=ss)
      cnt[x][y][1]=ss,cnt[x][y][0]=1; else
      cnt[x][y][0]++;
 }
int Solve(int x,int y)
 {
    int le=1,ri=1;
    sg[1][0]=x;sg[1][1]=y;sg[1][2]=p;Update(x,y);d[x][y]=true;
    for (;le<=ri;le++)
     if (sg[le][2])
      for (int i=0;i<4;i++)
       {
          int k=sg[le][0]+dir[i][0],l=sg[le][1]+dir[i][1];
          if (!Inspect(k,l)||d[k][l]||b[k][l]) continue;
          sg[++ri][0]=k;sg[ri][1]=l;sg[ri][2]=sg[le][2]-1;
          d[k][l]=true;Update(k,l);
       }
    for (int i=1;i<=ri;i++)
      d[sg[i][0]][sg[i][1]]=false;
    return ri;
 }
void Check(int x,int y)
 {
    if (s[x][y]==st)
      {cout <<x<<' '<<y<<' '<<x<<' '<<y<<endl;exit(0);}
    int le=1,ri=1;
    li[1][0]=x;li[1][1]=y;li[1][2]=p;c[x][y]=true;
    for (;le<=ri;le++)
     if (li[le][2])
      for (int i=0;i<4;i++)
       {
          int k=li[le][0]+dir[i][0],l=li[le][1]+dir[i][1];
          if (!Inspect(k,l)||c[k][l]||b[k][l]) continue;
          li[++ri][0]=k;li[ri][1]=l;li[ri][2]=li[le][2]-1;
          c[k][l]=true;
       }
    int now=0;ss++;
    for (int i=1;i<=st;i++)
     if (!c[Rat[i][0]][Rat[i][1]])
       now=Solve(Rat[i][0],Rat[i][1]);
    for (int i=1;i<=now;i++)
     if (cnt[sg[i][0]][sg[i][1]][0]+s[x][y]==st)
       {
          cout <<x<<' '<<y<<' '<<sg[i][0]<<' '<<sg[i][1]<<endl;
          exit(0);
       }
    for (int i=1;i<=ri;i++) c[li[i][0]][li[i][1]]=false;
 }
void Work()
 {
    if (st>=327) return;
    for (int i=1;i<=st;i++)
      BFS(Rat[i][0],Rat[i][1]);
    for (int i=1;i<=n;i++)
     for (int j=1;j<=m;j++)
      if (s[i][j]*2>=st) Check(i,j);
 }
int main()
 {
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    cin >>n>>m>>p;
    for (int i=1;i<=n;i++)
     {
        scanf("%s",a+1);
        for (int j=1;j<=m;j++)
         if (a[j]=='R') Rat[++st][0]=i,Rat[st][1]=j; else
         if (a[j]=='X') b[i][j]=true;
     }
    Work();
    puts("-1");
    return 0;
 }


#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 1050
int st,n,m,p,ss,Rat[N][2],s[N][N],li[N][3],sg[N][3];
bool b[N][N],c[N][N],d[N][N];char a[N];int cnt[N][N][2];
const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
inline bool Inspect(int x,int y)
 {return x>0&&y>0&&x<=n&&y<=m;}
void BFS(int x,int y)
 {
    int le=1,ri=1;
    li[1][0]=x;li[1][1]=y;li[1][2]=p;c[x][y]=true;s[x][y]++;
    for (;le<=ri;le++)
     if (li[le][2])
      for (int i=0;i<4;i++)
       {
          int k=li[le][0]+dir[i][0],l=li[le][1]+dir[i][1];
          if (!Inspect(k,l)||c[k][l]||b[k][l]) continue;
          li[++ri][0]=k;li[ri][1]=l;li[ri][2]=li[le][2]-1;
          c[k][l]=true;s[k][l]++;
       }
    for (int i=1;i<=ri;i++) c[li[i][0]][li[i][1]]=false;
 }
inline void Update(int x,int y)
 {
    if (cnt[x][y][1]!=ss)
      cnt[x][y][1]=ss,cnt[x][y][0]=1; else
      cnt[x][y][0]++;
 }
int Solve(int x,int y)
 {
    int le=1,ri=1;
    sg[1][0]=x;sg[1][1]=y;sg[1][2]=p;Update(x,y);d[x][y]=true;
    for (;le<=ri;le++)
     if (sg[le][2])
      for (int i=0;i<4;i++)
       {
          int k=sg[le][0]+dir[i][0],l=sg[le][1]+dir[i][1];
          if (!Inspect(k,l)||d[k][l]||b[k][l]) continue;
          sg[++ri][0]=k;sg[ri][1]=l;sg[ri][2]=sg[le][2]-1;
          d[k][l]=true;Update(k,l);
       }
    for (int i=1;i<=ri;i++)
      d[sg[i][0]][sg[i][1]]=false;
    return ri;
 }
void Check(int x,int y)
 {
    if (s[x][y]==st)
      {
         cout <<x<<' '<<y<<' ';
         for (int i=1;i<=n;i++)
          for (int j=1;j<=m;j++)
           if ((i!=x||j!=y)&&!b[i][j])
            {cout <<i<<' '<<j<<endl;exit(0);}
      }
    int le=1,ri=1;
    li[1][0]=x;li[1][1]=y;li[1][2]=p;c[x][y]=true;
    for (;le<=ri;le++)
     if (li[le][2])
      for (int i=0;i<4;i++)
       {
          int k=li[le][0]+dir[i][0],l=li[le][1]+dir[i][1];
          if (!Inspect(k,l)||c[k][l]||b[k][l]) continue;
          li[++ri][0]=k;li[ri][1]=l;li[ri][2]=li[le][2]-1;
          c[k][l]=true;
       }
    int now=0;ss++;
    for (int i=1;i<=st;i++)
     if (!c[Rat[i][0]][Rat[i][1]])
       now=Solve(Rat[i][0],Rat[i][1]);
    for (int i=1;i<=now;i++)
     if (cnt[sg[i][0]][sg[i][1]][0]+s[x][y]==st)
       {
          cout <<x<<' '<<y<<' '<<sg[i][0]<<' '<<sg[i][1]<<endl;
          exit(0);
       }
    for (int i=1;i<=ri;i++) c[li[i][0]][li[i][1]]=false;
 }
void Work()
 {
    if (st>=327) return;
    for (int i=1;i<=st;i++)
      BFS(Rat[i][0],Rat[i][1]);
    for (int i=1;i<=n;i++)
     for (int j=1;j<=m;j++)
      if (s[i][j]*2>=st) Check(i,j);
 }
int main()
 {
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    cin >>n>>m>>p;
    for (int i=1;i<=n;i++)
     {
        scanf("%s",a+1);
        for (int j=1;j<=m;j++)
         if (a[j]=='R') Rat[++st][0]=i,Rat[st][1]=j; else
         if (a[j]=='X') b[i][j]=true;
     }
    Work();
    puts("-1");
    return 0;
 }


#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 2050
int st,n,m,p,ss,Rat[N][2],s[N][N],li[N][3],sg[N][3];
bool b[N][N],c[N][N],d[N][N];char a[N];int cnt[N][N][2];
const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
inline bool Inspect(int x,int y)
 {return x>0&&y>0&&x<=n&&y<=m;}
void BFS(int x,int y)
 {
    int le=1,ri=1;
    li[1][0]=x;li[1][1]=y;li[1][2]=p;c[x][y]=true;s[x][y]++;
    for (;le<=ri;le++)
     if (li[le][2])
      for (int i=0;i<4;i++)
       {
          int k=li[le][0]+dir[i][0],l=li[le][1]+dir[i][1];
          if (!Inspect(k,l)||c[k][l]||b[k][l]) continue;
          li[++ri][0]=k;li[ri][1]=l;li[ri][2]=li[le][2]-1;
          c[k][l]=true;s[k][l]++;
       }
    for (int i=1;i<=ri;i++) c[li[i][0]][li[i][1]]=false;
 }
inline void Update(int x,int y)
 {
    if (cnt[x][y][1]!=ss)
      cnt[x][y][1]=ss,cnt[x][y][0]=1; else
      cnt[x][y][0]++;
 }
int Solve(int x,int y)
 {
    int le=1,ri=1;
    sg[1][0]=x;sg[1][1]=y;sg[1][2]=p;Update(x,y);d[x][y]=true;
    for (;le<=ri;le++)
     if (sg[le][2])
      for (int i=0;i<4;i++)
       {
          int k=sg[le][0]+dir[i][0],l=sg[le][1]+dir[i][1];
          if (!Inspect(k,l)||d[k][l]||b[k][l]) continue;
          sg[++ri][0]=k;sg[ri][1]=l;sg[ri][2]=sg[le][2]-1;
          d[k][l]=true;Update(k,l);
       }
    for (int i=1;i<=ri;i++)
      d[sg[i][0]][sg[i][1]]=false;
    return ri;
 }
void Check(int x,int y)
 {
    if (s[x][y]==st)
      {
         cout <<x<<' '<<y<<' ';
         for (int i=1;i<=n;i++)
          for (int j=1;j<=m;j++)
           if ((i!=x||j!=y)&&!b[i][j])
            {cout <<i<<' '<<j<<endl;exit(0);}
      }
    int le=1,ri=1;
    li[1][0]=x;li[1][1]=y;li[1][2]=p;c[x][y]=true;
    for (;le<=ri;le++)
     if (li[le][2])
      for (int i=0;i<4;i++)
       {
          int k=li[le][0]+dir[i][0],l=li[le][1]+dir[i][1];
          if (!Inspect(k,l)||c[k][l]||b[k][l]) continue;
          li[++ri][0]=k;li[ri][1]=l;li[ri][2]=li[le][2]-1;
          c[k][l]=true;
       }
    int now=0;ss++;
    for (int i=1;i<=st;i++)
     if (!c[Rat[i][0]][Rat[i][1]])
       now=Solve(Rat[i][0],Rat[i][1]);
    for (int i=1;i<=now;i++)
     if (cnt[sg[i][0]][sg[i][1]][0]+s[x][y]==st)
       {
          cout <<x<<' '<<y<<' '<<sg[i][0]<<' '<<sg[i][1]<<endl;
          exit(0);
       }
    for (int i=1;i<=ri;i++) c[li[i][0]][li[i][1]]=false;
 }
void Work()
 {
    for (int i=1;i<=st;i++)
      BFS(Rat[i][0],Rat[i][1]);
    for (int i=1;i<=n;i++)
     for (int j=1;j<=m;j++)
      if (s[i][j]*2>=st) Check(i,j);
 }
int main()
 {
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    cin >>n>>m>>p;
    for (int i=1;i<=n;i++)
     {
        scanf("%s",a+1);
        for (int j=1;j<=m;j++)
         if (a[j]=='R') Rat[++st][0]=i,Rat[st][1]=j; else
         if (a[j]=='X') b[i][j]=true;
        if (st>=327) {puts("-1");return 0;}
     }
    Work();
    puts("-1");
    return 0;
 }