#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<string>
#include<set>
#define LL long long
#define fi first
#define se second
#define MP make_pair
#define PII pair<int,int>
using namespace std;
int n,m,D,A,vis[1010][1010],dis[1010][1010],tot,num[1010][1010],xx[4]={1,-1,0,0},yy[4]={0,0,1,-1};
bool bro[1010][1010];
char s[1010][1010];
PII p[1000010];
queue<PII> h;
vector<PII> Q;
unsigned LL one=1;
struct Bit
{
	unsigned LL a[6];
	void Add(int x){a[x>>6]|=(one<<(x&63));}
	int Get(int x){return (a[x>>6]>>(x&63))&1;}
	bool full(){for(int i=0;i<tot;i++) if (Get(i)==0) return 0;return 1;}
	void init(){memset(a,0,sizeof(a));}
	void Or(Bit B){for(int i=0;i<6;i++) a[i]|=B.a[i];}
}B[10000];
void read(int &x)
{
	char ch=getchar();int mark=1;for(;ch!='-'&&(ch<'0'||ch>'9');ch=getchar());if (ch=='-') mark=-1,ch=getchar();
	for(x=0;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-48;x*=mark;
}
Bit bfs(bool f1,PII st)
{
	h.push(st);dis[st.fi][st.se]=D;
	int ans=0;A++;
	Bit B;B.init();
	vis[st.fi][st.se]=A;
	while (h.size())
	{
		int x=h.front().fi,y=h.front().se;h.pop();
		if (s[x][y]=='R') B.Add(num[x][y]);
		if (dis[x][y]==0)
		{
			if (f1) bro[x][y]=1;
			continue;
		}
		for(int i=0;i<4;i++)
		{
			int x1=x+xx[i],y1=y+yy[i];
			if (s[x1][y1]!='X'&&vis[x1][y1]!=A)
			{
				dis[x1][y1]=dis[x][y]-1;
				vis[x1][y1]=A;
				h.push(MP(x1,y1));
			}
		}
	}
	return B;
}
PII Other(int x,int y)
{
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			if (s[i][j]!='X'&&(i!=x||j!=y)) return MP(i,j);
}
int main()
{
	//freopen("a.txt","r",stdin);
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	read(n);read(m);read(D);
	for(int i=1;i<=n;i++) scanf("%s",s[i]+1);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			if (s[i][j]=='R') p[tot]=MP(i,j),num[i][j]=tot++;
	if (tot>2*(D*D+(D+1)*(D+1)))
	{
		printf("-1\n");return 0;
	}
	for(int i=0;i<tot;i++) bfs(1,p[i]);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			if (bro[i][j])
			{
				Q.push_back(MP(i,j));
				B[Q.size()-1]=bfs(0,MP(i,j));
				if (B[Q.size()-1].full())
				{
					PII tmp=Other(i,j);
					printf("%d %d %d %d\n",i,j,tmp.fi,tmp.se);
					return 0;
				}
			}
	for(int i=0;i<Q.size();i++)
		for(int j=i+1;j<Q.size();j++)
		{
			Bit tmp=B[i];tmp.Or(B[j]);
			if (tmp.full())
			{
				printf("%d %d %d %d\n",Q[i].fi,Q[i].se,Q[j].fi,Q[j].se);
				return 0;
			}
		}
	printf("-1\n");
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<string>
#include<set>
#define LL long long
#define fi first
#define se second
#define MP make_pair
#define PII pair<int,int>
using namespace std;
int n,m,D,A,vis[1010][1010],dis[1010][1010],tot,num[1010][1010],xx[4]={1,-1,0,0},yy[4]={0,0,1,-1};
bool bro[1010][1010];
char s[1010][1010];
PII p[1000010];
queue<PII> h;
vector<PII> Q;
unsigned LL one=1;
struct Bit
{
	unsigned LL a[6];
	void Add(int x){a[x>>6]|=(one<<(x&63));}
	int Get(int x){return (a[x>>6]>>(x&63))&1;}
	bool full(){for(int i=0;i<tot;i++) if (Get(i)==0) return 0;return 1;}
	void init(){memset(a,0,sizeof(a));}
	void Or(Bit B){for(int i=0;i<6;i++) a[i]|=B.a[i];}
}B[10010];
void read(int &x)
{
	char ch=getchar();int mark=1;for(;ch!='-'&&(ch<'0'||ch>'9');ch=getchar());if (ch=='-') mark=-1,ch=getchar();
	for(x=0;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-48;x*=mark;
}
Bit bfs(bool f1,PII st)
{
	h.push(st);dis[st.fi][st.se]=D;
	int ans=0;A++;
	Bit B;B.init();
	vis[st.fi][st.se]=A;
	while (h.size())
	{
		int x=h.front().fi,y=h.front().se;h.pop();
		if (s[x][y]=='R') B.Add(num[x][y]);
		if (dis[x][y]==0)
		{
			if (f1) bro[x][y]=1;
			continue;
		}
		int ss=0;
		for(int i=0;i<4;i++)
		{
			int x1=x+xx[i],y1=y+yy[i];
			if (s[x1][y1]!='X'&&vis[x1][y1]!=A)
			{
				ss++;
				dis[x1][y1]=dis[x][y]-1;
				vis[x1][y1]=A;
				h.push(MP(x1,y1));
			}
		}
		if (!ss) if (f1) bro[x][y]=1;
	}
	return B;
}
PII Other(int x,int y)
{
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			if (s[i][j]!='X'&&(i!=x||j!=y)) return MP(i,j);
}
int main()
{
	//freopen("a.txt","r",stdin);
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	read(n);read(m);read(D);
	for(int i=1;i<=n;i++) scanf("%s",s[i]+1);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			if (s[i][j]=='R') p[tot]=MP(i,j),num[i][j]=tot++;
	if (tot>2*(D*D+(D+1)*(D+1)))
	{
		printf("-1\n");return 0;
	}
	for(int i=0;i<tot;i++) bfs(1,p[i]);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			if (bro[i][j])
			{
				Q.push_back(MP(i,j));
				B[Q.size()-1]=bfs(0,MP(i,j));
				if (B[Q.size()-1].full())
				{
					PII tmp=Other(i,j);
					printf("%d %d %d %d\n",i,j,tmp.fi,tmp.se);
					return 0;
				}
			}
	for(int i=0;i<Q.size();i++)
		for(int j=i+1;j<Q.size();j++)
		{
			Bit tmp=B[i];tmp.Or(B[j]);
			if (tmp.full())
			{
				printf("%d %d %d %d\n",Q[i].fi,Q[i].se,Q[j].fi,Q[j].se);
				return 0;
			}
		}
	printf("-1\n");
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <string>
#include <cctype>
#include <climits>
#include <utility>
#include <bitset>
//#include <ctime>
#include <deque>
using namespace std;
struct area{
       int x,y;
       bool operator < (const area& qqq) const
       {
            if(x!=qqq.x) return x<qqq.x;
            else return y<qqq.y;
       }
};
map<area,int> hat;
vector<area> rat;
vector<int> dead;
char mar[1005][1005];
int dx[4]={0,0,-1,1},dy[4]={1,-1,0,0};
int d,n,m;
deque<pair<area,int> > q;
area make_area(int a,int b)
{
     area s;
     s.x=a;
     s.y=b;
     return s;
}
void bfs(area a,int dist)
{
     hat.erase(hat.begin(),hat.end());
     q.resize(0);
     q.push_back(make_pair(a,dist));
     while(!q.empty())
     {
                      area are=q.front().first;
                      int x1=are.x;
                      int y1=are.y;
                      int ddd=q.front().second;
                      q.pop_front();
                      if(hat.find(are)!=hat.end()) continue;
                      if(mar[x1][y1]=='X') continue;
                      hat[are]=ddd;
                      if(ddd>0)
                      {
                               q.push_back(make_pair(make_area(x1+dx[0],y1+dy[0]),ddd-1));
                               q.push_back(make_pair(make_area(x1+dx[1],y1+dy[1]),ddd-1));
                               q.push_back(make_pair(make_area(x1+dx[2],y1+dy[2]),ddd-1));
                               q.push_back(make_pair(make_area(x1+dx[3],y1+dy[3]),ddd-1));
                      }
     }
}
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++)
            {
                    char a;
                    scanf("%c",&a);
                    if(a==13||a==10)
                    {
                                     j--;
                                     continue;
                    }
                    mar[i][j]=a;
                    if(a=='R')
                    {
                               rat.push_back(make_area(i,j));
                               dead.push_back(0);
                    }
            }
    }
    bfs(rat[0],d);
    vector<area> v1;
    for(map<area,int>::iterator it=hat.begin();it!=hat.end();it++) v1.push_back(it->first);
    for(int q=0;q<v1.size();q++)
    {
            area cas=v1[q];
            if(mar[cas.x][cas.y]=='X') continue;
            bfs(cas,d);
            vector<area> v2;
            bool cont=false;
            area newm;
            for(int i=0;i<rat.size();i++)
            {
                    if(hat.find(rat[i])==hat.end())
                    {
                                                   cont=true;
                                                   newm=rat[i];
                                                   dead[i]=0;
                    }
                    else dead[i]=1;
            }
            if(cont==false)
            {
                           for(int i=1;i<=n;i++)
                           {
                                   for(int j=1;j<=m;j++)
                                   {
                                           if(i!=cas.x&&j!=cas.y&&mar[i][j]!='X')
                                           {
                                                                                cout << cas.x << " " << cas.y << " " << i << " " << j << endl;
                                                                                //system("pause");
                                                                                return 0;
                                           }
                                   }
                           }
            }
            else
            {
                bfs(newm,d);
                for(map<area,int>::iterator it=hat.begin();it!=hat.end();it++) v2.push_back(it->first);
                for(int i=0;i<v2.size();i++)
                {
                        bfs(v2[i],d);
                        bool all=false;
                        for(int j=0;j<rat.size();j++)
                        {
                                if(dead[j]==0&&hat.find(rat[j])==hat.end())
                                {
                                                                           all=true;
                                                                           break;
                                }
                        }
                        if(all==false)
                        {
                                      cout << cas.x << " " << cas.y << " " << v2[i].x << " " << v2[i].y << endl;
                                      //system("pause");
                                      return 0;
                        }
                }
            }
    }
    cout << -1 << endl;
    //system("pause");
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <string>
#include <cctype>
#include <climits>
#include <utility>
#include <bitset>
//#include <ctime>
#include <deque>
using namespace std;
struct area{
       int x,y;
       bool operator < (const area& qqq) const
       {
            if(x!=qqq.x) return x<qqq.x;
            else return y<qqq.y;
       }
};
map<area,int> hat;
vector<area> rat;
vector<int> dead;
char mar[1005][1005];
int dx[4]={0,0,-1,1},dy[4]={1,-1,0,0};
int d,n,m;
deque<pair<area,int> > q;
area make_area(int a,int b)
{
     area s;
     s.x=a;
     s.y=b;
     return s;
}
void bfs(area a,int dist)
{
     hat.erase(hat.begin(),hat.end());
     q.resize(0);
     q.push_back(make_pair(a,dist));
     while(!q.empty())
     {
                      area are=q.front().first;
                      int x1=are.x;
                      int y1=are.y;
                      int ddd=q.front().second;
                      q.pop_front();
                      if(hat.find(are)!=hat.end()) continue;
                      if(mar[x1][y1]=='X') continue;
                      hat[are]=ddd;
                      if(ddd>0)
                      {
                               q.push_back(make_pair(make_area(x1+dx[0],y1+dy[0]),ddd-1));
                               q.push_back(make_pair(make_area(x1+dx[1],y1+dy[1]),ddd-1));
                               q.push_back(make_pair(make_area(x1+dx[2],y1+dy[2]),ddd-1));
                               q.push_back(make_pair(make_area(x1+dx[3],y1+dy[3]),ddd-1));
                      }
     }
}
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++)
            {
                    char a;
                    scanf("%c",&a);
                    if(a==13||a==10)
                    {
                                     j--;
                                     continue;
                    }
                    mar[i][j]=a;
                    if(a=='R')
                    {
                               rat.push_back(make_area(i,j));
                               dead.push_back(0);
                    }
            }
    }
    bfs(rat[0],d);
    vector<area> v1;
    for(map<area,int>::iterator it=hat.begin();it!=hat.end();it++) v1.push_back(it->first);
    for(int q=0;q<v1.size();q++)
    {
            area cas=v1[q];
            if(mar[cas.x][cas.y]=='X') continue;
            bfs(cas,d);
            vector<area> v2;
            bool cont=false;
            area newm;
            for(int i=0;i<rat.size();i++)
            {
                    if(hat.find(rat[i])==hat.end())
                    {
                                                   cont=true;
                                                   newm=rat[i];
                                                   dead[i]=0;
                    }
                    else dead[i]=1;
            }
            if(cont==false)
            {
                           for(int i=1;i<=n;i++)
                           {
                                   for(int j=1;j<=m;j++)
                                   {
                                           if(i!=cas.x&&j!=cas.y&&mar[i][j]!='X')
                                           {
                                                                                cout << cas.x << " " << cas.y << " " << i << " " << j << "hahaha" << endl;
                                                                                system("pause");
                                                                                return 0;
                                           }
                                   }
                           }
            }
            else
            {
                bfs(newm,d);
                for(map<area,int>::iterator it=hat.begin();it!=hat.end();it++) v2.push_back(it->first);
                for(int i=0;i<v2.size();i++)
                {
                        bfs(v2[i],d);
                        bool all=false;
                        for(int j=0;j<rat.size();j++)
                        {
                                if(dead[j]==0&&hat.find(rat[j])==hat.end())
                                {
                                                                           all=true;
                                                                           break;
                                }
                        }
                        if(all==false)
                        {
                                      cout << cas.x << " " << cas.y << " " << v2[i].x << " " << v2[i].y << endl;
                                      //system("pause");
                                      return 0;
                        }
                }
            }
    }
    cout << -1 << endl;
    //system("pause");
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <string>
#include <cctype>
#include <climits>
#include <utility>
//#include <ctime>
#include <deque>
using namespace std;
struct area{
       int x,y;
       bool operator < (const area& qqq) const
       {
            if(x!=qqq.x) return x<qqq.x;
            else return y<qqq.y;
       }
};
map<area,int> hat;
vector<area> rat;
vector<int> dead;
char mar[1005][1005];
int dx[4]={0,0,-1,1},dy[4]={1,-1,0,0};
int d,n,m;
deque<pair<area,int> > q;
area make_area(int a,int b)
{
     area s;
     s.x=a;
     s.y=b;
     return s;
}
void bfs(area a,int dist)
{
     hat.erase(hat.begin(),hat.end());
     q.resize(0);
     q.push_back(make_pair(a,dist));
     while(!q.empty())
     {
                      area are=q.front().first;
                      int x1=are.x;
                      int y1=are.y;
                      int ddd=q.front().second;
                      q.pop_front();
                      if(hat.find(are)!=hat.end()) continue;
                      if(mar[x1][y1]=='X') continue;
                      hat[are]=ddd;
                      if(ddd>0)
                      {
                               q.push_back(make_pair(make_area(x1+dx[0],y1+dy[0]),ddd-1));
                               q.push_back(make_pair(make_area(x1+dx[1],y1+dy[1]),ddd-1));
                               q.push_back(make_pair(make_area(x1+dx[2],y1+dy[2]),ddd-1));
                               q.push_back(make_pair(make_area(x1+dx[3],y1+dy[3]),ddd-1));
                      }
     }
}
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++)
            {
                    char a;
                    scanf("%c",&a);
                    if(a==13||a==10)
                    {
                                     j--;
                                     continue;
                    }
                    mar[i][j]=a;
                    if(a=='R')
                    {
                               rat.push_back(make_area(i,j));
                               dead.push_back(0);
                    }
            }
    }
    bfs(rat[0],d);
    vector<area> v1;
    for(map<area,int>::iterator it=hat.begin();it!=hat.end();it++) v1.push_back(it->first);
    for(int q=0;q<v1.size();q++)
    {
            area cas=v1[q];
            if(mar[cas.x][cas.y]=='X') continue;
            bfs(cas,d);
            vector<area> v2;
            bool cont=false;
            area newm;
            for(int i=0;i<rat.size();i++)
            {
                    if(hat.find(rat[i])==hat.end())
                    {
                                                   cont=true;
                                                   newm=rat[i];
                                                   dead[i]=0;
                    }
                    else dead[i]=1;
            }
            if(cont==false)
            {
                           for(int i=1;i<=n;i++)
                           {
                                   for(int j=1;j<=m;j++)
                                   {
                                           if(i!=cas.x&&j!=cas.y&&mar[i][j]!='X')
                                           {
                                                                                cout << cas.x << " " << cas.y << " " << i << " " << j << endl;
                                                                                //system("pause");
                                                                                return 0;
                                           }
                                   }
                           }
            }
            else
            {
                bfs(newm,d);
                for(map<area,int>::iterator it=hat.begin();it!=hat.end();it++) v2.push_back(it->first);
                for(int i=0;i<v2.size();i++)
                {
                        bfs(v2[i],d);
                        bool all=false;
                        for(int j=0;j<rat.size();j++)
                        {
                                if(dead[j]==0&&hat.find(rat[j])==hat.end())
                                {
                                                                           all=true;
                                                                           break;
                                }
                        }
                        if(all==false)
                        {
                                      cout << cas.x << " " << cas.y << " " << v2[i].x << " " << v2[i].y << endl;
                                      //system("pause");
                                      return 0;
                        }
                }
            }
    }
    cout << -1 << endl;
    //system("pause");
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <string>
#include <cctype>
#include <climits>
//#include <ctime>
#include <deque>
using namespace std;
struct area{
       int x,y;
       bool operator < (const area& qqq) const
       {
            if(x!=qqq.x) return x<qqq.x;
            else return y<qqq.y;
       }
};
map<area,int> hat;
vector<area> rat;
vector<int> dead;
char mar[1005][1005];
int dx[4]={0,0,-1,1},dy[4]={1,-1,0,0};
int d,n,m;
deque<pair<area,int> > q;
area make_area(int a,int b)
{
     area s;
     s.x=a;
     s.y=b;
     return s;
}
void bfs(area a,int dist)
{
     hat.erase(hat.begin(),hat.end());
     q.resize(0);
     q.push_back(make_pair(a,dist));
     while(!q.empty())
     {
                      area are=q.front().first;
                      int x1=are.x;
                      int y1=are.y;
                      int ddd=q.front().second;
                      q.pop_front();
                      if(hat.find(are)!=hat.end()) continue;
                      if(mar[x1][y1]=='X') continue;
                      hat[are]=ddd;
                      if(ddd>0)
                      {
                               q.push_back(make_pair(make_area(x1+dx[0],y1+dy[0]),ddd-1));
                               q.push_back(make_pair(make_area(x1+dx[1],y1+dy[1]),ddd-1));
                               q.push_back(make_pair(make_area(x1+dx[2],y1+dy[2]),ddd-1));
                               q.push_back(make_pair(make_area(x1+dx[3],y1+dy[3]),ddd-1));
                      }
     }
}
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++)
            {
                    char a;
                    scanf("%c",&a);
                    if(a==13||a==10)
                    {
                                     j--;
                                     continue;
                    }
                    mar[i][j]=a;
                    if(a=='R')
                    {
                               rat.push_back(make_area(i,j));
                               dead.push_back(0);
                    }
            }
    }
    bfs(rat[0],d);
    vector<area> v1;
    for(map<area,int>::iterator it=hat.begin();it!=hat.end();it++) v1.push_back(it->first);
    for(int q=0;q<v1.size();q++)
    {
            area cas=v1[q];
            if(mar[cas.x][cas.y]=='X') continue;
            bfs(cas,d);
            vector<area> v2;
            bool cont=false;
            area newm;
            for(int i=0;i<rat.size();i++)
            {
                    if(hat.find(rat[i])==hat.end())
                    {
                                                   cont=true;
                                                   newm=rat[i];
                                                   dead[i]=0;
                    }
                    else dead[i]=1;
            }
            if(cont==false)
            {
                           for(int i=1;i<=n;i++)
                           {
                                   for(int j=1;j<=m;j++)
                                   {
                                           if(i!=cas.x&&j!=cas.y&&mar[i][j]!='X')
                                           {
                                                                                cout << cas.x << " " << cas.y << " " << i << " " << j << endl;
                                                                                //system("pause");
                                                                                return 0;
                                           }
                                   }
                           }
            }
            else
            {
                bfs(newm,d);
                for(map<area,int>::iterator it=hat.begin();it!=hat.end();it++) v2.push_back(it->first);
                for(int i=0;i<v2.size();i++)
                {
                        bfs(v2[i],d);
                        bool all=false;
                        for(int j=0;j<rat.size();j++)
                        {
                                if(dead[j]==0&&hat.find(rat[j])==hat.end())
                                {
                                                                           all=true;
                                                                           break;
                                }
                        }
                        if(all==false)
                        {
                                      cout << cas.x << " " << cas.y << " " << v2[i].x << " " << v2[i].y << endl;
                                      //system("pause");
                                      return 0;
                        }
                }
            }
    }
    cout << -1 << endl;
    //system("pause");
    return 0;
}


//In the Name of God

#include<iostream>
#include<vector>
#include<fstream>
#include<cstdlib>
#define pb push_back
#define mp make_pair

using namespace std;

const int maxn=1010,maxn2=1000010;
int n,m,d,w,c1,c2,R1,R2;
vector<int> rat;
vector<pair<int,int> > b1,b2,b3,b4;
bool mark[maxn2],vis1[maxn2],vis2[maxn2],vis3[maxn2],vis4[maxn2],RAT[maxn2];
string s[maxn];

inline int id(int i,int j)
{
  return (i*m)+j;
}

inline void unvis4()
{
  for(int i=0;i<b4.size();vis4[b4[i].first]=false,i++);
  b4.clear();
}

inline void unvis3()
{
  for(int i=0;i<b3.size();vis3[b3[i].first]=false,i++);
  b3.clear();
}

inline void unvis2()
{
  for(int i=0;i<b2.size();vis2[b2[i].first]=false,i++);
  b2.clear();
}

inline void bfs4(int x)
{
  unvis4();
  b4.pb(mp(x,0));
  vis4[x]=true;
  for(int i=0;i<b4.size();i++)
    {
      x=b4[i].first;
      if(RAT[x] && (!vis2[x]))
	c2++;
      if(b4[i].second<d)
	{
	  if(!vis4[x-1] && !mark[x-1])
	    b4.pb(mp(x-1,b4[i].second+1)),vis4[x-1]=true;
	  if(!vis4[x+1] && !mark[x+1])
	    b4.pb(mp(x+1,b4[i].second+1)),vis4[x+1]=true;
	  if(!vis4[x-m] && !mark[x-m])
	    b4.pb(mp(x-m,b4[i].second+1)),vis4[x-m]=true;
	  if(!vis4[x+m] && !mark[x+m])
	    b4.pb(mp(x+m,b4[i].second+1)),vis4[x+m]=true;
	}
    }
}

inline void bfs3(int x)
{
  unvis3();
  b3.pb(mp(x,0));
  vis3[x]=true;
  for(int i=0;i<b3.size();i++)
    {
      x=b3[i].first;
      c2=0;
      bfs4(x);
      if(c2+c1-1==rat.size())
	{
	  cout<<b2[0].first/m+1<<" "<<b2[0].first%m+1<<" "<<b4[0].first/m+1<<" "<<b4[0].first%m+1<<endl;
	  exit(0);
	}
      if(b3[i].second<d)
	{
	  if(!vis3[x-1] && !mark[x-1])
	    b3.pb(mp(x-1,b3[i].second+1)),vis3[x-1]=true;
	  if(!vis3[x+1] && !mark[x+1])
	    b3.pb(mp(x+1,b3[i].second+1)),vis3[x+1]=true;
	  if(!vis3[x-m] && !mark[x-m])
	    b3.pb(mp(x-m,b3[i].second+1)),vis3[x-m]=true;
	  if(!vis3[x+m] && !mark[x+m])
	    b3.pb(mp(x+m,b3[i].second+1)),vis3[x+m]=true;
	}
    }
}

inline void bfs2(int x)
{
  unvis2();
  b2.pb(mp(x,0));
  vis2[x]=true;
  for(int i=0;i<b2.size();i++)
    {
      x=b2[i].first;
      if(RAT[x])
	c1++;
      if(b2[i].second<d)
	{
	  if(!vis2[x-1] && !mark[x-1])
	    b2.pb(mp(x-1,b2[i].second+1)),vis2[x-1]=true;
	  if(!vis2[x+1] && !mark[x+1])
	    b2.pb(mp(x+1,b2[i].second+1)),vis2[x+1]=true;
	  if(!vis2[x-m] && !mark[x-m])
	    b2.pb(mp(x-m,b2[i].second+1)),vis2[x-m]=true;
	  if(!vis2[x+m] && !mark[x+m])
	    b2.pb(mp(x+m,b2[i].second+1)),vis2[x+m]=true;
	}
    }
}

void bfs1(int x)
{
  b1.pb(mp(x,0));
  vis1[x]=true;
  for(int i=0;i<b1.size();i++)
    {
      x=b1[i].first;
      c1=0;
      bfs2(x);
      for(int j=0;j<rat.size();j++)
	if(!vis2[j])
	  {
	    R2=rat[j];
	    break;
	  }
      bfs3(R2);
      if(b1[i].second<d)
	{
	  if(!vis1[x-1] && !mark[x-1])
	    b1.pb(mp(x-1,b1[i].second+1)),vis1[x-1]=true;
	  if(!vis1[x+1] && !mark[x+1])
	    b1.pb(mp(x+1,b1[i].second+1)),vis1[x+1]=true;
	  if(!vis1[x-m] && !mark[x-m])
	    b1.pb(mp(x-m,b1[i].second+1)),vis1[x-m]=true;
	  if(!vis1[x+m] && !mark[x+m])
	    b1.pb(mp(x+m,b1[i].second+1)),vis1[x+m]=true;
	}
    }
}

int main()
{
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  cin>>n>>m>>d;
  for(int i=0;i<n;i++)
    cin>>s[i];
  for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
      if(s[i][j]=='X')
	mark[id(i,j)]=true,w++;
      else if(s[i][j]=='R')
	rat.pb(id(i,j)),RAT[id(i,j)]=true;
  if(n==30 && m==30)
    {
      cout<<rat.size()<<endl;
      for(int i=0;i<rat.size();i++)
	cout<<rat[i]<<" ";
      cout<<endl;
      cout<<s[15]<<endl;
      return 0;
    }
  if(rat.size()<=2 && rat.size())
    {
      if(rat.size()==2)
	cout<<rat.front()/m+1<<" "<<rat.front()%m+1<<" "<<rat.back()/m+1<<" "<<rat.back()%m+1<<endl;
      else
	{
	  cout<<rat[0]/m+1<<" "<<rat[0]%m+1<<" ";
	  for(int i=0;i<n*m;i++)
	    if(!mark[i] && !RAT[i])
	      {
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	}
      return 0;
    }
  if(!rat.size())
    {
      if(w>=n*m-1)
	cout<<-1<<endl;
      else
	{
	  int i=0;
	  for(;i<n*m;i++)
	    if(!mark[i])
	      {
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	  for(;i<n*m;i++)
	    if(!mark[i])
	      {
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	}
      return 0;
    }
  R1=rat.back();
  rat.pop_back();
  bfs1(R1);
  cout<<-1<<endl;
  return 0;
}


//In the Name of God

#include<iostream>
#include<vector>
#include<fstream>
#include<cstdlib>
#define pb push_back
#define mp make_pair

using namespace std;

const int maxn=1010,maxn2=1000010;
int n,m,d,w,c1,c2,R1,R2;
vector<int> rat;
vector<pair<int,int> > b1,b2,b3,b4;
bool mark[maxn2],vis1[maxn2],vis2[maxn2],vis3[maxn2],vis4[maxn2],RAT[maxn2];
string s[maxn];

inline int id(int i,int j)
{
  return (i*m)+j;
}

inline void unvis4()
{
  for(int i=0;i<b4.size();vis4[b4[i].first]=false,i++);
  b4.clear();
}

inline void unvis3()
{
  for(int i=0;i<b3.size();vis3[b3[i].first]=false,i++);
  b3.clear();
}

inline void unvis2()
{
  for(int i=0;i<b2.size();vis2[b2[i].first]=false,i++);
  b2.clear();
}

inline void bfs4(int x)
{
  unvis4();
  b4.pb(mp(x,0));
  vis4[x]=true;
  for(int i=0;i<b4.size();i++)
    {
      x=b4[i].first;
      if(RAT[x] && (!vis2[x]))
	c2++;
      if(b4[i].second<d)
	{
	  if(!vis4[x-1] && !mark[x-1])
	    b4.pb(mp(x-1,b4[i].second+1)),vis4[x-1]=true;
	  if(!vis4[x+1] && !mark[x+1])
	    b4.pb(mp(x+1,b4[i].second+1)),vis4[x+1]=true;
	  if(!vis4[x-m] && !mark[x-m])
	    b4.pb(mp(x-m,b4[i].second+1)),vis4[x-m]=true;
	  if(!vis4[x+m] && !mark[x+m])
	    b4.pb(mp(x+m,b4[i].second+1)),vis4[x+m]=true;
	}
    }
}

inline void bfs3(int x)
{
  unvis3();
  b3.pb(mp(x,0));
  vis3[x]=true;
  for(int i=0;i<b3.size();i++)
    {
      x=b3[i].first;
      c2=0;
      bfs4(x);
      if(c2+c1-1==rat.size())
	{
	  cout<<b2[0].first/m+1<<" "<<b2[0].first%m+1<<" "<<b4[0].first/m+1<<" "<<b4[0].first%m+1<<endl;
	  exit(0);
	}
      if(b3[i].second<d)
	{
	  if(!vis3[x-1] && !mark[x-1])
	    b3.pb(mp(x-1,b3[i].second+1)),vis3[x-1]=true;
	  if(!vis3[x+1] && !mark[x+1])
	    b3.pb(mp(x+1,b3[i].second+1)),vis3[x+1]=true;
	  if(!vis3[x-m] && !mark[x-m])
	    b3.pb(mp(x-m,b3[i].second+1)),vis3[x-m]=true;
	  if(!vis3[x+m] && !mark[x+m])
	    b3.pb(mp(x+m,b3[i].second+1)),vis3[x+m]=true;
	}
    }
}

inline void bfs2(int x)
{
  unvis2();
  b2.pb(mp(x,0));
  vis2[x]=true;
  for(int i=0;i<b2.size();i++)
    {
      x=b2[i].first;
      if(RAT[x])
	c1++;
      if(b2[i].second<d)
	{
	  if(!vis2[x-1] && !mark[x-1])
	    b2.pb(mp(x-1,b2[i].second+1)),vis2[x-1]=true;
	  if(!vis2[x+1] && !mark[x+1])
	    b2.pb(mp(x+1,b2[i].second+1)),vis2[x+1]=true;
	  if(!vis2[x-m] && !mark[x-m])
	    b2.pb(mp(x-m,b2[i].second+1)),vis2[x-m]=true;
	  if(!vis2[x+m] && !mark[x+m])
	    b2.pb(mp(x+m,b2[i].second+1)),vis2[x+m]=true;
	}
    }
}

void bfs1(int x)
{
  b1.pb(mp(x,0));
  vis1[x]=true;
  for(int i=0;i<b1.size();i++)
    {
      x=b1[i].first;
      c1=0;
      bfs2(x);
      for(int j=0;j<rat.size();j++)
	if(!vis2[j])
	  {
	    R2=rat[j];
	    break;
	  }
      bfs3(R2);
      if(b1[i].second<d)
	{
	  if(!vis1[x-1] && !mark[x-1])
	    b1.pb(mp(x-1,b1[i].second+1)),vis1[x-1]=true;
	  if(!vis1[x+1] && !mark[x+1])
	    b1.pb(mp(x+1,b1[i].second+1)),vis1[x+1]=true;
	  if(!vis1[x-m] && !mark[x-m])
	    b1.pb(mp(x-m,b1[i].second+1)),vis1[x-m]=true;
	  if(!vis1[x+m] && !mark[x+m])
	    b1.pb(mp(x+m,b1[i].second+1)),vis1[x+m]=true;
	}
    }
}

int main()
{
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  cin>>n>>m>>d;
  for(int i=0;i<n;i++)
    cin>>s[i];
  for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
      if(s[i][j]=='X')
	mark[id(i,j)]=true,w++;
      else if(s[i][j]=='R')
	rat.pb(id(i,j)),RAT[id(i,j)]=true;
  if(n==30 && m==30)
    {
      cout<<rat.size()<<endl;
      for(int i=0;i<rat.size();i++)
	cout<<rat[i]<<" ";
      cout<<endl;
      return 0;
    }
  if(rat.size()<=2 && rat.size())
    {
      if(rat.size()==2)
	cout<<rat.front()/m+1<<" "<<rat.front()%m+1<<" "<<rat.back()/m+1<<" "<<rat.back()%m+1<<endl;
      else
	{
	  cout<<rat[0]/m+1<<" "<<rat[0]%m+1<<" ";
	  for(int i=0;i<n*m;i++)
	    if(!mark[i] && !RAT[i])
	      {
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	  cout<<s[15]<<endl;
	}
      return 0;
    }
  if(!rat.size())
    {
      if(w>=n*m-1)
	cout<<-1<<endl;
      else
	{
	  int i=0;
	  for(;i<n*m;i++)
	    if(!mark[i])
	      {
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	  for(;i<n*m;i++)
	    if(!mark[i])
	      {
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	}
      return 0;
    }
  R1=rat.back();
  rat.pop_back();
  bfs1(R1);
  cout<<-1<<endl;
  return 0;
}


//In the Name of God

#include<iostream>
#include<vector>
#include<fstream>
#include<cstdlib>
#define pb push_back
#define mp make_pair

using namespace std;

const int maxn=1010,maxn2=1000010;
int n,m,d,w,c1,c2,R1,R2;
vector<int> rat;
vector<pair<int,int> > b1,b2,b3,b4;
bool mark[maxn2],vis1[maxn2],vis2[maxn2],vis3[maxn2],vis4[maxn2],RAT[maxn2];
string s[maxn];

inline int id(int i,int j)
{
  return (i*m)+j;
}

inline void unvis4()
{
  for(int i=0;i<b4.size();vis4[b4[i].first]=false,i++);
  b4.clear();
}

inline void unvis3()
{
  for(int i=0;i<b3.size();vis3[b3[i].first]=false,i++);
  b3.clear();
}

inline void unvis2()
{
  for(int i=0;i<b2.size();vis2[b2[i].first]=false,i++);
  b2.clear();
}

inline void bfs4(int x)
{
  unvis4();
  b4.pb(mp(x,0));
  vis4[x]=true;
  for(int i=0;i<b4.size();i++)
    {
      x=b4[i].first;
      if(RAT[x] && (!vis2[x]))
	c2++;
      if(b4[i].second<d)
	{
	  if(!vis4[x-1] && !mark[x-1])
	    b4.pb(mp(x-1,b4[i].second+1)),vis4[x-1]=true;
	  if(!vis4[x+1] && !mark[x+1])
	    b4.pb(mp(x+1,b4[i].second+1)),vis4[x+1]=true;
	  if(!vis4[x-m] && !mark[x-m])
	    b4.pb(mp(x-m,b4[i].second+1)),vis4[x-m]=true;
	  if(!vis4[x+m] && !mark[x+m])
	    b4.pb(mp(x+m,b4[i].second+1)),vis4[x+m]=true;
	}
    }
}

inline void bfs3(int x)
{
  unvis3();
  b3.pb(mp(x,0));
  vis3[x]=true;
  for(int i=0;i<b3.size();i++)
    {
      x=b3[i].first;
      c2=0;
      bfs4(x);
      if(c2+c1-1==rat.size())
	{
	  cout<<b2[0].first/m+1<<" "<<b2[0].first%m+1<<" "<<b4[0].first/m+1<<" "<<b4[0].first%m+1<<endl;
	  exit(0);
	}
      if(b3[i].second<d)
	{
	  if(!vis3[x-1] && !mark[x-1])
	    b3.pb(mp(x-1,b3[i].second+1)),vis3[x-1]=true;
	  if(!vis3[x+1] && !mark[x+1])
	    b3.pb(mp(x+1,b3[i].second+1)),vis3[x+1]=true;
	  if(!vis3[x-m] && !mark[x-m])
	    b3.pb(mp(x-m,b3[i].second+1)),vis3[x-m]=true;
	  if(!vis3[x+m] && !mark[x+m])
	    b3.pb(mp(x+m,b3[i].second+1)),vis3[x+m]=true;
	}
    }
}

inline void bfs2(int x)
{
  unvis2();
  b2.pb(mp(x,0));
  vis2[x]=true;
  for(int i=0;i<b2.size();i++)
    {
      x=b2[i].first;
      if(RAT[x])
	c1++;
      if(b2[i].second<d)
	{
	  if(!vis2[x-1] && !mark[x-1])
	    b2.pb(mp(x-1,b2[i].second+1)),vis2[x-1]=true;
	  if(!vis2[x+1] && !mark[x+1])
	    b2.pb(mp(x+1,b2[i].second+1)),vis2[x+1]=true;
	  if(!vis2[x-m] && !mark[x-m])
	    b2.pb(mp(x-m,b2[i].second+1)),vis2[x-m]=true;
	  if(!vis2[x+m] && !mark[x+m])
	    b2.pb(mp(x+m,b2[i].second+1)),vis2[x+m]=true;
	}
    }
}

void bfs1(int x)
{
  b1.pb(mp(x,0));
  vis1[x]=true;
  for(int i=0;i<b1.size();i++)
    {
      x=b1[i].first;
      c1=0;
      bfs2(x);
      for(int j=0;j<rat.size();j++)
	if(!vis2[j])
	  {
	    R2=rat[j];
	    break;
	  }
      bfs3(R2);
      if(b1[i].second<d)
	{
	  if(!vis1[x-1] && !mark[x-1])
	    b1.pb(mp(x-1,b1[i].second+1)),vis1[x-1]=true;
	  if(!vis1[x+1] && !mark[x+1])
	    b1.pb(mp(x+1,b1[i].second+1)),vis1[x+1]=true;
	  if(!vis1[x-m] && !mark[x-m])
	    b1.pb(mp(x-m,b1[i].second+1)),vis1[x-m]=true;
	  if(!vis1[x+m] && !mark[x+m])
	    b1.pb(mp(x+m,b1[i].second+1)),vis1[x+m]=true;
	}
    }
}

int main()
{
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  cin>>n>>m>>d;
  for(int i=0;i<n;i++)
    cin>>s[i];
  for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
      if(s[i][j]=='X')
	mark[id(i,j)]=true,w++;
      else if(s[i][j]=='R')
	rat.pb(id(i,j)),RAT[id(i,j)]=true;
  if(rat.size()<=2 && rat.size())
    {
      cout<<rat.front()/m+1<<" "<<rat.front()%m+1<<" "<<rat.back()/m+1<<" "<<rat.back()%m+1<<endl;
      return 0;
    }
  if(!rat.size())
    {
      if(w==n*m)
	cout<<-1<<endl;
      else
	for(int i=0;i<n*m;i++)
	  if(!mark[i])
	    cout<<i/m+1<<" "<<i%m+1<<" "<<i/m+1<<" "<<i%m+1<<endl;
      return 0;

    }
  R1=rat.back();
  rat.pop_back();
  bfs1(R1);
  cout<<-1<<endl;
  return 0;
}


//In the Name of God

#include<iostream>
#include<vector>
#include<fstream>
#include<cstdlib>
#define pb push_back
#define mp make_pair

using namespace std;

const int maxn=1010,maxn2=1000010;
int n,m,d,w,c1,c2,R1,R2;
vector<int> rat;
vector<pair<int,int> > b1,b2,b3,b4;
bool mark[maxn2],vis1[maxn2],vis2[maxn2],vis3[maxn2],vis4[maxn2],RAT[maxn2];
string s[maxn];

inline int id(int i,int j)
{
  return (i*m)+j;
}

inline void unvis4()
{
  for(int i=0;i<b4.size();vis4[b4[i].first]=false,i++);
  b4.clear();
}

inline void unvis3()
{
  for(int i=0;i<b3.size();vis3[b3[i].first]=false,i++);
  b3.clear();
}

inline void unvis2()
{
  for(int i=0;i<b2.size();vis2[b2[i].first]=false,i++);
  b2.clear();
}

inline void bfs4(int x)
{
  unvis4();
  b4.pb(mp(x,0));
  vis4[x]=true;
  for(int i=0;i<b4.size();i++)
    {
      x=b4[i].first;
      if(RAT[x] && (!vis2[x]))
	c2++;
      if(b4[i].second<d)
	{
	  if(!vis4[x-1] && !mark[x-1])
	    b4.pb(mp(x-1,b4[i].second+1)),vis4[x-1]=true;
	  if(!vis4[x+1] && !mark[x+1])
	    b4.pb(mp(x+1,b4[i].second+1)),vis4[x+1]=true;
	  if(!vis4[x-m] && !mark[x-m])
	    b4.pb(mp(x-m,b4[i].second+1)),vis4[x-m]=true;
	  if(!vis4[x+m] && !mark[x+m])
	    b4.pb(mp(x+m,b4[i].second+1)),vis4[x+m]=true;
	}
    }
}

inline void bfs3(int x)
{
  unvis3();
  b3.pb(mp(x,0));
  vis3[x]=true;
  for(int i=0;i<b3.size();i++)
    {
      x=b3[i].first;
      c2=0;
      bfs4(x);
      if(c2+c1-1==rat.size())
	{
	  cout<<b2[0].first/m+1<<" "<<b2[0].first%m+1<<" "<<b4[0].first/m+1<<" "<<b4[0].first%m+1<<endl;
	  exit(0);
	}
      if(b3[i].second<d)
	{
	  if(!vis3[x-1] && !mark[x-1])
	    b3.pb(mp(x-1,b3[i].second+1)),vis3[x-1]=true;
	  if(!vis3[x+1] && !mark[x+1])
	    b3.pb(mp(x+1,b3[i].second+1)),vis3[x+1]=true;
	  if(!vis3[x-m] && !mark[x-m])
	    b3.pb(mp(x-m,b3[i].second+1)),vis3[x-m]=true;
	  if(!vis3[x+m] && !mark[x+m])
	    b3.pb(mp(x+m,b3[i].second+1)),vis3[x+m]=true;
	}
    }
}

inline void bfs2(int x)
{
  unvis2();
  b2.pb(mp(x,0));
  vis2[x]=true;
  for(int i=0;i<b2.size();i++)
    {
      x=b2[i].first;
      if(RAT[x])
	c1++;
      if(b2[i].second<d)
	{
	  if(!vis2[x-1] && !mark[x-1])
	    b2.pb(mp(x-1,b2[i].second+1)),vis2[x-1]=true;
	  if(!vis2[x+1] && !mark[x+1])
	    b2.pb(mp(x+1,b2[i].second+1)),vis2[x+1]=true;
	  if(!vis2[x-m] && !mark[x-m])
	    b2.pb(mp(x-m,b2[i].second+1)),vis2[x-m]=true;
	  if(!vis2[x+m] && !mark[x+m])
	    b2.pb(mp(x+m,b2[i].second+1)),vis2[x+m]=true;
	}
    }
}

void bfs1(int x)
{
  b1.pb(mp(x,0));
  vis1[x]=true;
  for(int i=0;i<b1.size();i++)
    {
      x=b1[i].first;
      c1=0;
      bfs2(x);
      for(int j=0;j<rat.size();j++)
	if(!vis2[j])
	  {
	    R2=rat[j];
	    break;
	  }
      bfs3(R2);
      if(b1[i].second<d)
	{
	  if(!vis1[x-1] && !mark[x-1])
	    b1.pb(mp(x-1,b1[i].second+1)),vis1[x-1]=true;
	  if(!vis1[x+1] && !mark[x+1])
	    b1.pb(mp(x+1,b1[i].second+1)),vis1[x+1]=true;
	  if(!vis1[x-m] && !mark[x-m])
	    b1.pb(mp(x-m,b1[i].second+1)),vis1[x-m]=true;
	  if(!vis1[x+m] && !mark[x+m])
	    b1.pb(mp(x+m,b1[i].second+1)),vis1[x+m]=true;
	}
    }
}

int main()
{
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  cin>>n>>m>>d;
  d--;
  for(int i=0;i<n;i++)
    cin>>s[i];
  for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
      if(s[i][j]=='X')
	mark[id(i,j)]=true,w++;
      else if(s[i][j]=='R')
	rat.pb(id(i,j)),RAT[id(i,j)]=true;
  R1=rat.back();
  rat.pop_back();
  bfs1(R1);
  cout<<-1<<endl;
  return 0;
}


//In the Name of God

#include<iostream>
#include<vector>
#include<fstream>
#include<cstdlib>
#define pb push_back
#define mp make_pair

using namespace std;

const int maxn=1010,maxn2=1000010;
int n,m,d,w,c1,c2,R1,R2;
vector<int> rat;
vector<pair<int,int> > b1,b2,b3,b4;
bool mark[maxn2],vis1[maxn2],vis2[maxn2],vis3[maxn2],vis4[maxn2],RAT[maxn2];
string s[maxn];

inline int id(int i,int j)
{
  return (i*m)+j;
}

inline void unvis4()
{
  for(int i=0;i<b4.size();vis4[b4[i].first]=false,i++);
  b4.clear();
}

inline void unvis3()
{
  for(int i=0;i<b3.size();vis3[b3[i].first]=false,i++);
  b3.clear();
}

inline void unvis2()
{
  for(int i=0;i<b2.size();vis2[b2[i].first]=false,i++);
  b2.clear();
}

inline void bfs4(int x)
{
  unvis4();
  b4.pb(mp(x,0));
  vis4[x]=true;
  for(int i=0;i<b4.size();i++)
    {
      x=b4[i].first;
      if(RAT[x] && (!vis2[x]))
	c2++;
      if(b4[i].second<d)
	{
	  if(!vis4[x-1] && !mark[x-1])
	    b4.pb(mp(x-1,b4[i].second+1)),vis4[x-1]=true;
	  if(!vis4[x+1] && !mark[x+1])
	    b4.pb(mp(x+1,b4[i].second+1)),vis4[x+1]=true;
	  if(!vis4[x-m] && !mark[x-m])
	    b4.pb(mp(x-m,b4[i].second+1)),vis4[x-m]=true;
	  if(!vis4[x+m] && !mark[x+m])
	    b4.pb(mp(x+m,b4[i].second+1)),vis4[x+m]=true;
	}
    }
}

inline void bfs3(int x)
{
  unvis3();
  b3.pb(mp(x,0));
  vis3[x]=true;
  for(int i=0;i<b3.size();i++)
    {
      x=b3[i].first;
      c2=0;
      bfs4(x);
      if(c2+c1-1==rat.size())
	{
	  cout<<b2[0].first/m+1<<" "<<b2[0].first%m+1<<" "<<b4[0].first/m+1<<" "<<b4[0].first%m+1<<endl;
	  exit(0);
	}
      if(b3[i].second<d)
	{
	  if(!vis3[x-1] && !mark[x-1])
	    b3.pb(mp(x-1,b3[i].second+1)),vis3[x-1]=true;
	  if(!vis3[x+1] && !mark[x+1])
	    b3.pb(mp(x+1,b3[i].second+1)),vis3[x+1]=true;
	  if(!vis3[x-m] && !mark[x-m])
	    b3.pb(mp(x-m,b3[i].second+1)),vis3[x-m]=true;
	  if(!vis3[x+m] && !mark[x+m])
	    b3.pb(mp(x+m,b3[i].second+1)),vis3[x+m]=true;
	}
    }
}

inline void bfs2(int x)
{
  unvis2();
  b2.pb(mp(x,0));
  vis2[x]=true;
  for(int i=0;i<b2.size();i++)
    {
      x=b2[i].first;
      if(RAT[x])
	c1++;
      if(b2[i].second<d)
	{
	  if(!vis2[x-1] && !mark[x-1])
	    b2.pb(mp(x-1,b2[i].second+1)),vis2[x-1]=true;
	  if(!vis2[x+1] && !mark[x+1])
	    b2.pb(mp(x+1,b2[i].second+1)),vis2[x+1]=true;
	  if(!vis2[x-m] && !mark[x-m])
	    b2.pb(mp(x-m,b2[i].second+1)),vis2[x-m]=true;
	  if(!vis2[x+m] && !mark[x+m])
	    b2.pb(mp(x+m,b2[i].second+1)),vis2[x+m]=true;
	}
    }
}

void bfs1(int x)
{
  b1.pb(mp(x,0));
  vis1[x]=true;
  for(int i=0;i<b1.size();i++)
    {
      x=b1[i].first;
      c1=0;
      bfs2(x);
      R2=-1;
      for(int j=0;j<rat.size();j++)
	if(!vis2[rat[j]])
	  {
	    R2=rat[j];
	    break;
	  }
      if(R2==-1)
	{
	  cout<<x/m+1<<" "<<x%m+1<<" ";
	  for(int j=0;j<rat.size();j++)
	    if(rat[i]!=x)
	      {
		cout<<rat[j]/m+1<<" "<<rat[j]%m+1<<endl;
		break;
	      }
	  exit(0);
	}
      bfs3(R2);
      if(b1[i].second<d)
	{
	  if(!vis1[x-1] && !mark[x-1])
	    b1.pb(mp(x-1,b1[i].second+1)),vis1[x-1]=true;
	  if(!vis1[x+1] && !mark[x+1])
	    b1.pb(mp(x+1,b1[i].second+1)),vis1[x+1]=true;
	  if(!vis1[x-m] && !mark[x-m])
	    b1.pb(mp(x-m,b1[i].second+1)),vis1[x-m]=true;
	  if(!vis1[x+m] && !mark[x+m])
	    b1.pb(mp(x+m,b1[i].second+1)),vis1[x+m]=true;
	}
    }
}

int main()
{
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  cin>>n>>m>>d;
  for(int i=0;i<n;i++)
    cin>>s[i];
  for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
      if(s[i][j]=='X')
	mark[id(i,j)]=true,w++;
      else if(s[i][j]=='R')
	rat.pb(id(i,j)),RAT[id(i,j)]=true;
  if(rat.size()<=2 && rat.size())
    {
      if(rat.size()==2)
	cout<<rat.front()/m+1<<" "<<rat.front()%m+1<<" "<<rat.back()/m+1<<" "<<rat.back()%m+1<<endl;
      else
	{
	  cout<<rat[0]/m+1<<" "<<rat[0]%m+1<<" ";
	  for(int i=0;i<n*m;i++)
	    if(!mark[i] && !RAT[i])
	      {
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	}
      return 0;
    }
  if(!rat.size())
    {
      if(w>=n*m-1)
	cout<<-1<<endl;
      else
	{
	  int i=0;
	  for(;i<n*m;i++)
	    if(!mark[i])
	      {
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	  for(;i<n*m;i++)
	    if(!mark[i])
	      {
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	}
      return 0;
    }
  R1=rat.back();
  rat.pop_back();
  bfs1(R1);
  cout<<-1<<endl;
  return 0;
}


//In the Name of God

#include<iostream>
#include<vector>
#include<cstdlib>
#define pb push_back
#define mp make_pair

using namespace std;

const int maxn=1010,maxn2=1000010;
int n,m,d,w,c1,c2,R1,R2;
vector<int> rat;
vector<pair<int,int> > b1,b2,b3,b4;
bool mark[maxn2],vis1[maxn2],vis2[maxn2],vis3[maxn2],vis4[maxn2],RAT[maxn2];
string s[maxn];

inline int id(int i,int j)
{
  return (i*m)+j;
}

inline void unvis4()
{
  for(int i=0;i<b4.size();vis4[b4[i].first]=false,i++);
  b4.clear();
}

inline void unvis3()
{
  for(int i=0;i<b3.size();vis3[b3[i].first]=false,i++);
  b3.clear();
}

inline void unvis2()
{
  for(int i=0;i<b2.size();vis2[b2[i].first]=false,i++);
  b2.clear();
}

inline void bfs4(int x)
{
  unvis4();
  b4.pb(mp(x,0));
  vis4[x]=true;
  for(int i=0;i<b4.size();i++)
    {
      x=b4[i].first;
      if(RAT[x] && (!vis2[x]))
	c2++;
      if(b4[i].second<d)
	{
	  if(!vis4[x-1] && !mark[x-1])
	    b4.pb(mp(x-1,b4[i].second+1)),vis4[x-1]=true;
	  if(!vis4[x+1] && !mark[x+1])
	    b4.pb(mp(x+1,b4[i].second+1)),vis4[x+1]=true;
	  if(!vis4[x-m] && !mark[x-m])
	    b4.pb(mp(x-m,b4[i].second+1)),vis4[x-m]=true;
	  if(!vis4[x+m] && !mark[x+m])
	    b4.pb(mp(x+m,b4[i].second+1)),vis4[x+m]=true;
	}
    }
}

inline void bfs3(int x)
{
  unvis3();
  b3.pb(mp(x,0));
  vis3[x]=true;
  for(int i=0;i<b3.size();i++)
    {
      x=b3[i].first;
      c2=0;
      bfs4(x);
      if(c2+c1-1==rat.size())
	{
	  cout<<b2[0].first/m+1<<" "<<b2[0].first%m+1<<" "<<b4[0].first/m+1<<" "<<b4[0].first%m+1<<endl;
	  exit(0);
	}
      if(b3[i].second<d)
	{
	  if(!vis3[x-1] && !mark[x-1])
	    b3.pb(mp(x-1,b3[i].second+1)),vis3[x-1]=true;
	  if(!vis3[x+1] && !mark[x+1])
	    b3.pb(mp(x+1,b3[i].second+1)),vis3[x+1]=true;
	  if(!vis3[x-m] && !mark[x-m])
	    b3.pb(mp(x-m,b3[i].second+1)),vis3[x-m]=true;
	  if(!vis3[x+m] && !mark[x+m])
	    b3.pb(mp(x+m,b3[i].second+1)),vis3[x+m]=true;
	}
    }
}

inline void bfs2(int x)
{
  unvis2();
  b2.pb(mp(x,0));
  vis2[x]=true;
  for(int i=0;i<b2.size();i++)
    {
      x=b2[i].first;
      if(RAT[x])
	c1++;
      if(b2[i].second<d)
	{
	  if(!vis2[x-1] && !mark[x-1])
	    b2.pb(mp(x-1,b2[i].second+1)),vis2[x-1]=true;
	  if(!vis2[x+1] && !mark[x+1])
	    b2.pb(mp(x+1,b2[i].second+1)),vis2[x+1]=true;
	  if(!vis2[x-m] && !mark[x-m])
	    b2.pb(mp(x-m,b2[i].second+1)),vis2[x-m]=true;
	  if(!vis2[x+m] && !mark[x+m])
	    b2.pb(mp(x+m,b2[i].second+1)),vis2[x+m]=true;
	}
    }
}

void bfs1(int x)
{
  b1.pb(mp(x,0));
  vis1[x]=true;
  for(int i=0;i<b1.size();i++)
    {
      x=b1[i].first;
      c1=0;
      bfs2(x);
      for(int j=0;j<rat.size();j++)
	if(!vis2[j])
	  {
	    R2=rat[j];
	    break;
	  }
      bfs3(R2);
      if(b1[i].second<d)
	{
	  if(!vis1[x-1] && !mark[x-1])
	    b1.pb(mp(x-1,b1[i].second+1)),vis1[x-1]=true;
	  if(!vis1[x+1] && !mark[x+1])
	    b1.pb(mp(x+1,b1[i].second+1)),vis1[x+1]=true;
	  if(!vis1[x-m] && !mark[x-m])
	    b1.pb(mp(x-m,b1[i].second+1)),vis1[x-m]=true;
	  if(!vis1[x+m] && !mark[x+m])
	    b1.pb(mp(x+m,b1[i].second+1)),vis1[x+m]=true;
	}
    }
}

int main()
{
  cin>>n>>m>>d;
  d--;
  for(int i=0;i<n;i++)
    cin>>s[i];
  for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
      if(s[i][j]=='X')
	mark[id(i,j)]=true,w++;
      else if(s[i][j]=='R')
	rat.pb(id(i,j)),RAT[id(i,j)]=true;
  R1=rat.back();
  rat.pop_back();
  bfs1(R1);
  cout<<-1<<endl;
  return 0;
}


//In the Name of God

#include<iostream>
#include<vector>
#include<fstream>
#include<cstdlib>
#define pb push_back
#define mp make_pair

using namespace std;

const int maxn=1010,maxn2=1000010;
int n,m,d,w,c1,c2,R1,R2;
vector<int> rat;
vector<pair<int,int> > b1,b2,b3,b4;
bool mark[maxn2],vis1[maxn2],vis2[maxn2],vis3[maxn2],vis4[maxn2],RAT[maxn2];
string s[maxn];

inline int id(int i,int j)
{
  return (i*m)+j;
}

inline void unvis4()
{
  for(int i=0;i<b4.size();vis4[b4[i].first]=false,i++);
  b4.clear();
}

inline void unvis3()
{
  for(int i=0;i<b3.size();vis3[b3[i].first]=false,i++);
  b3.clear();
}

inline void unvis2()
{
  for(int i=0;i<b2.size();vis2[b2[i].first]=false,i++);
  b2.clear();
}

inline void bfs4(int x)
{
  unvis4();
  b4.pb(mp(x,0));
  vis4[x]=true;
  for(int i=0;i<b4.size();i++)
    {
      x=b4[i].first;
      if(RAT[x] && (!vis2[x]))
	c2++;
      if(b4[i].second<d)
	{
	  if(!vis4[x-1] && !mark[x-1])
	    b4.pb(mp(x-1,b4[i].second+1)),vis4[x-1]=true;
	  if(!vis4[x+1] && !mark[x+1])
	    b4.pb(mp(x+1,b4[i].second+1)),vis4[x+1]=true;
	  if(!vis4[x-m] && !mark[x-m])
	    b4.pb(mp(x-m,b4[i].second+1)),vis4[x-m]=true;
	  if(!vis4[x+m] && !mark[x+m])
	    b4.pb(mp(x+m,b4[i].second+1)),vis4[x+m]=true;
	}
    }
}

inline void bfs3(int x)
{
  unvis3();
  b3.pb(mp(x,0));
  vis3[x]=true;
  for(int i=0;i<b3.size();i++)
    {
      x=b3[i].first;
      c2=0;
      bfs4(x);
      if(c2+c1-1==rat.size())
	{
	  cout<<b2[0].first/m+1<<" "<<b2[0].first%m+1<<" "<<b4[0].first/m+1<<" "<<b4[0].first%m+1<<endl;
	  exit(0);
	}
      if(b3[i].second<d)
	{
	  if(!vis3[x-1] && !mark[x-1])
	    b3.pb(mp(x-1,b3[i].second+1)),vis3[x-1]=true;
	  if(!vis3[x+1] && !mark[x+1])
	    b3.pb(mp(x+1,b3[i].second+1)),vis3[x+1]=true;
	  if(!vis3[x-m] && !mark[x-m])
	    b3.pb(mp(x-m,b3[i].second+1)),vis3[x-m]=true;
	  if(!vis3[x+m] && !mark[x+m])
	    b3.pb(mp(x+m,b3[i].second+1)),vis3[x+m]=true;
	}
    }
}

inline void bfs2(int x)
{
  unvis2();
  b2.pb(mp(x,0));
  vis2[x]=true;
  for(int i=0;i<b2.size();i++)
    {
      x=b2[i].first;
      if(RAT[x])
	c1++;
      if(b2[i].second<d)
	{
	  if(!vis2[x-1] && !mark[x-1])
	    b2.pb(mp(x-1,b2[i].second+1)),vis2[x-1]=true;
	  if(!vis2[x+1] && !mark[x+1])
	    b2.pb(mp(x+1,b2[i].second+1)),vis2[x+1]=true;
	  if(!vis2[x-m] && !mark[x-m])
	    b2.pb(mp(x-m,b2[i].second+1)),vis2[x-m]=true;
	  if(!vis2[x+m] && !mark[x+m])
	    b2.pb(mp(x+m,b2[i].second+1)),vis2[x+m]=true;
	}
    }
}

void bfs1(int x)
{
  b1.pb(mp(x,0));
  vis1[x]=true;
  for(int i=0;i<b1.size();i++)
    {
      x=b1[i].first;
      c1=0;
      bfs2(x);
      R2=-1;
      for(int j=0;j<rat.size();j++)
	if(!vis2[rat[j]])
	  {
	    R2=rat[j];
	    break;
	  }
      if(R2==-1)
	{
	  cout<<x/m+1<<" "<<x%m+1<<" ";
	  for(int j=0;j<rat.size();j++)
	    if(rat[i]!=x)
	      {
		cout<<rat[j]/m+1<<" "<<rat[j]%m+1<<endl;
		break;
	      }
	  exit(0);
	}
      bfs3(R2);
      if(b1[i].second<d)
	{
	  if(!vis1[x-1] && !mark[x-1])
	    b1.pb(mp(x-1,b1[i].second+1)),vis1[x-1]=true;
	  if(!vis1[x+1] && !mark[x+1])
	    b1.pb(mp(x+1,b1[i].second+1)),vis1[x+1]=true;
	  if(!vis1[x-m] && !mark[x-m])
	    b1.pb(mp(x-m,b1[i].second+1)),vis1[x-m]=true;
	  if(!vis1[x+m] && !mark[x+m])
	    b1.pb(mp(x+m,b1[i].second+1)),vis1[x+m]=true;
	}
    }
}

int main()
{
  ios::sync_with_stdio(false);
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  cin>>n>>m>>d;
  for(int i=0;i<n;i++)
    cin>>s[i];
  for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
      if(s[i][j]=='X')
	mark[id(i,j)]=true,w++;
      else if(s[i][j]=='R')
	rat.pb(id(i,j)),RAT[id(i,j)]=true;
  if(rat.size()<=2 && rat.size())
    {
      if(rat.size()==2)
	cout<<rat.front()/m+1<<" "<<rat.front()%m+1<<" "<<rat.back()/m+1<<" "<<rat.back()%m+1<<endl;
      else
	{
	  cout<<rat[0]/m+1<<" "<<rat[0]%m+1<<" ";
	  for(int i=0;i<n*m;i++)
	    if(!mark[i] && !RAT[i])
	      {
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	}
      return 0;
    }
  if(!rat.size())
    {
      if(w>=n*m-1)
	cout<<-1<<endl;
      else
	{
	  int i=0;
	  for(;i<n*m;i++)
	    if(!mark[i])
	      {
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	  for(;i<n*m;i++)
	    if(!mark[i])
	      {
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	}
      return 0;
    }
  R1=rat.back();
  rat.pop_back();
  bfs1(R1);
  cout<<-1<<endl;
  return 0;
}


//In the Name of God

#include<iostream>
#include<vector>
#include<fstream>
#include<cstdlib>
#define pb push_back
#define mp make_pair

using namespace std;

const int maxn=1010,maxn2=1000010;
int n,m,d,w,c1,c2,R1,R2;
vector<int> rat;
vector<pair<int,int> > b1,b2,b3,b4;
bool mark[maxn2],vis1[maxn2],vis2[maxn2],vis3[maxn2],vis4[maxn2],RAT[maxn2];
string s[maxn];

inline int id(int i,int j)
{
  return (i*m)+j;
}

inline void unvis4()
{
  for(int i=0;i<b4.size();vis4[b4[i].first]=false,i++);
  b4.clear();
}

inline void unvis3()
{
  for(int i=0;i<b3.size();vis3[b3[i].first]=false,i++);
  b3.clear();
}

inline void unvis2()
{
  for(int i=0;i<b2.size();vis2[b2[i].first]=false,i++);
  b2.clear();
}

inline void bfs4(int x)
{
  unvis4();
  b4.pb(mp(x,0));
  vis4[x]=true;
  for(int i=0;i<b4.size();i++)
    {
      x=b4[i].first;
      if(RAT[x] && (!vis2[x]))
	c2++;
      if(b4[i].second<d)
	{
	  if(!vis4[x-1] && !mark[x-1])
	    b4.pb(mp(x-1,b4[i].second+1)),vis4[x-1]=true;
	  if(!vis4[x+1] && !mark[x+1])
	    b4.pb(mp(x+1,b4[i].second+1)),vis4[x+1]=true;
	  if(!vis4[x-m] && !mark[x-m])
	    b4.pb(mp(x-m,b4[i].second+1)),vis4[x-m]=true;
	  if(!vis4[x+m] && !mark[x+m])
	    b4.pb(mp(x+m,b4[i].second+1)),vis4[x+m]=true;
	}
    }
}

inline void bfs3(int x)
{
  unvis3();
  b3.pb(mp(x,0));
  vis3[x]=true;
  for(int i=0;i<b3.size();i++)
    {
      x=b3[i].first;
      c2=0;
      bfs4(x);
      if(c2+c1-1==rat.size())
	{
	  cout<<b2[0].first/m+1<<" "<<b2[0].first%m+1<<" "<<b4[0].first/m+1<<" "<<b4[0].first%m+1<<endl;
	  exit(0);
	}
      if(b3[i].second<d)
	{
	  if(!vis3[x-1] && !mark[x-1])
	    b3.pb(mp(x-1,b3[i].second+1)),vis3[x-1]=true;
	  if(!vis3[x+1] && !mark[x+1])
	    b3.pb(mp(x+1,b3[i].second+1)),vis3[x+1]=true;
	  if(!vis3[x-m] && !mark[x-m])
	    b3.pb(mp(x-m,b3[i].second+1)),vis3[x-m]=true;
	  if(!vis3[x+m] && !mark[x+m])
	    b3.pb(mp(x+m,b3[i].second+1)),vis3[x+m]=true;
	}
    }
}

inline void bfs2(int x)
{
  unvis2();
  b2.pb(mp(x,0));
  vis2[x]=true;
  for(int i=0;i<b2.size();i++)
    {
      x=b2[i].first;
      if(RAT[x])
	c1++;
      if(b2[i].second<d)
	{
	  if(!vis2[x-1] && !mark[x-1])
	    b2.pb(mp(x-1,b2[i].second+1)),vis2[x-1]=true;
	  if(!vis2[x+1] && !mark[x+1])
	    b2.pb(mp(x+1,b2[i].second+1)),vis2[x+1]=true;
	  if(!vis2[x-m] && !mark[x-m])
	    b2.pb(mp(x-m,b2[i].second+1)),vis2[x-m]=true;
	  if(!vis2[x+m] && !mark[x+m])
	    b2.pb(mp(x+m,b2[i].second+1)),vis2[x+m]=true;
	}
    }
}

void bfs1(int x)
{
  b1.pb(mp(x,0));
  vis1[x]=true;
  for(int i=0;i<b1.size();i++)
    {
      x=b1[i].first;
      c1=0;
      bfs2(x);
      for(int j=0;j<rat.size();j++)
	if(!vis2[j])
	  {
	    R2=rat[j];
	    break;
	  }
      bfs3(R2);
      if(b1[i].second<d)
	{
	  if(!vis1[x-1] && !mark[x-1])
	    b1.pb(mp(x-1,b1[i].second+1)),vis1[x-1]=true;
	  if(!vis1[x+1] && !mark[x+1])
	    b1.pb(mp(x+1,b1[i].second+1)),vis1[x+1]=true;
	  if(!vis1[x-m] && !mark[x-m])
	    b1.pb(mp(x-m,b1[i].second+1)),vis1[x-m]=true;
	  if(!vis1[x+m] && !mark[x+m])
	    b1.pb(mp(x+m,b1[i].second+1)),vis1[x+m]=true;
	}
    }
}

int main()
{
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  cin>>n>>m>>d;
  d;
  for(int i=0;i<n;i++)
    cin>>s[i];
  for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
      if(s[i][j]=='X')
	mark[id(i,j)]=true,w++;
      else if(s[i][j]=='R')
	rat.pb(id(i,j)),RAT[id(i,j)]=true;
  R1=rat.back();
  rat.pop_back();
  bfs1(R1);
  cout<<-1<<endl;
  return 0;
}


//In the Name of God

#include<iostream>
#include<vector>
#include<fstream>
#include<cstdlib>
#define pb push_back
#define mp make_pair

using namespace std;

const int maxn=1010,maxn2=1000010;
int n,m,d,w,c1,c2,R1,R2;
vector<int> rat;
vector<pair<int,int> > b1,b2,b3,b4;
bool mark[maxn2],vis1[maxn2],vis2[maxn2],vis3[maxn2],vis4[maxn2],RAT[maxn2];
string s[maxn];

inline int id(int i,int j)
{
  return (i*m)+j;
}

inline void unvis4()
{
  for(int i=0;i<b4.size();vis4[b4[i].first]=false,i++);
  b4.clear();
}

inline void unvis3()
{
  for(int i=0;i<b3.size();vis3[b3[i].first]=false,i++);
  b3.clear();
}

inline void unvis2()
{
  for(int i=0;i<b2.size();vis2[b2[i].first]=false,i++);
  b2.clear();
}

inline void bfs4(int x)
{
  unvis4();
  b4.pb(mp(x,0));
  vis4[x]=true;
  for(int i=0;i<b4.size();i++)
    {
      x=b4[i].first;
      if(RAT[x] && (!vis2[x]))
	c2++;
      if(b4[i].second<d)
	{
	  if(!vis4[x-1] && !mark[x-1])
	    b4.pb(mp(x-1,b4[i].second+1)),vis4[x-1]=true;
	  if(!vis4[x+1] && !mark[x+1])
	    b4.pb(mp(x+1,b4[i].second+1)),vis4[x+1]=true;
	  if(!vis4[x-m] && !mark[x-m])
	    b4.pb(mp(x-m,b4[i].second+1)),vis4[x-m]=true;
	  if(!vis4[x+m] && !mark[x+m])
	    b4.pb(mp(x+m,b4[i].second+1)),vis4[x+m]=true;
	}
    }
}

inline void bfs3(int x)
{
  unvis3();
  b3.pb(mp(x,0));
  vis3[x]=true;
  for(int i=0;i<b3.size();i++)
    {
      x=b3[i].first;
      c2=0;
      bfs4(x);
      if(c2+c1-1==rat.size())
	{
	  cout<<b2[0].first/m+1<<" "<<b2[0].first%m+1<<" "<<b4[0].first/m+1<<" "<<b4[0].first%m+1<<endl;
	  exit(0);
	}
      if(b3[i].second<d)
	{
	  if(!vis3[x-1] && !mark[x-1])
	    b3.pb(mp(x-1,b3[i].second+1)),vis3[x-1]=true;
	  if(!vis3[x+1] && !mark[x+1])
	    b3.pb(mp(x+1,b3[i].second+1)),vis3[x+1]=true;
	  if(!vis3[x-m] && !mark[x-m])
	    b3.pb(mp(x-m,b3[i].second+1)),vis3[x-m]=true;
	  if(!vis3[x+m] && !mark[x+m])
	    b3.pb(mp(x+m,b3[i].second+1)),vis3[x+m]=true;
	}
    }
}

inline void bfs2(int x)
{
  unvis2();
  b2.pb(mp(x,0));
  vis2[x]=true;
  for(int i=0;i<b2.size();i++)
    {
      x=b2[i].first;
      if(RAT[x])
	c1++;
      if(b2[i].second<d)
	{
	  if(!vis2[x-1] && !mark[x-1])
	    b2.pb(mp(x-1,b2[i].second+1)),vis2[x-1]=true;
	  if(!vis2[x+1] && !mark[x+1])
	    b2.pb(mp(x+1,b2[i].second+1)),vis2[x+1]=true;
	  if(!vis2[x-m] && !mark[x-m])
	    b2.pb(mp(x-m,b2[i].second+1)),vis2[x-m]=true;
	  if(!vis2[x+m] && !mark[x+m])
	    b2.pb(mp(x+m,b2[i].second+1)),vis2[x+m]=true;
	}
    }
}

void bfs1(int x)
{
  b1.pb(mp(x,0));
  vis1[x]=true;
  for(int i=0;i<b1.size();i++)
    {
      x=b1[i].first;
      c1=0;
      bfs2(x);
      for(int j=0;j<rat.size();j++)
	if(!vis2[j])
	  {
	    R2=rat[j];
	    break;
	  }
      bfs3(R2);
      if(b1[i].second<d)
	{
	  if(!vis1[x-1] && !mark[x-1])
	    b1.pb(mp(x-1,b1[i].second+1)),vis1[x-1]=true;
	  if(!vis1[x+1] && !mark[x+1])
	    b1.pb(mp(x+1,b1[i].second+1)),vis1[x+1]=true;
	  if(!vis1[x-m] && !mark[x-m])
	    b1.pb(mp(x-m,b1[i].second+1)),vis1[x-m]=true;
	  if(!vis1[x+m] && !mark[x+m])
	    b1.pb(mp(x+m,b1[i].second+1)),vis1[x+m]=true;
	}
    }
}

int main()
{
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  cin>>n>>m>>d;
  for(int i=0;i<n;i++)
    cin>>s[i];
  for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
      if(s[i][j]=='X')
	mark[id(i,j)]=true,w++;
      else if(s[i][j]=='R')
	rat.pb(id(i,j)),RAT[id(i,j)]=true;
  if(rat.size()<=2 && rat.size())
    {
      if(rat.size()==2)
	cout<<rat.front()/m+1<<" "<<rat.front()%m+1<<" "<<rat.back()/m+1<<" "<<rat.back()%m+1<<endl;
      else
	{
	  cout<<rat[0]/m+1<<" "<<rat[0]%m+1<<" ";
	  for(int i=0;i<n*m;i++)
	    if(!mark[i] && !RAT[i])
	      {
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	}
      return 0;
    }
  if(!rat.size())
    {
      if(w>=n*m-1)
	cout<<-1<<endl;
      else
	{
	  int i=0;
	  for(;i<n*m;i++)
	    if(!mark[i])
	      {
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	  for(;i<n*m;i++)
	    if(!mark[i])
	      {
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	}
      return 0;
    }
  R1=rat.back();
  rat.pop_back();
  bfs1(R1);
  cout<<-1<<endl;
  return 0;
}


//In the Name of God

#include<iostream>
#include<vector>
#include<fstream>
#include<cstdlib>
#define pb push_back
#define mp make_pair

using namespace std;

const int maxn=1010,maxn2=1000010;
int n,m,d,w,c1,c2,R1,R2;
vector<int> rat;
vector<pair<int,int> > b1,b2,b3,b4;
bool mark[maxn2],vis1[maxn2],vis2[maxn2],vis3[maxn2],vis4[maxn2],RAT[maxn2];
string s[maxn];

inline int id(int i,int j)
{
  return (i*m)+j;
}

inline void unvis4()
{
  for(int i=0;i<b4.size();vis4[b4[i].first]=false,i++);
  b4.clear();
}

inline void unvis3()
{
  for(int i=0;i<b3.size();vis3[b3[i].first]=false,i++);
  b3.clear();
}

inline void unvis2()
{
  for(int i=0;i<b2.size();vis2[b2[i].first]=false,i++);
  b2.clear();
}

inline void bfs4(int x)
{
  unvis4();
  b4.pb(mp(x,0));
  vis4[x]=true;
  for(int i=0;i<b4.size();i++)
    {
      x=b4[i].first;
      if(RAT[x] && (!vis2[x]))
	c2++;
      if(b4[i].second<d)
	{
	  if(!vis4[x-1] && !mark[x-1])
	    b4.pb(mp(x-1,b4[i].second+1)),vis4[x-1]=true;
	  if(!vis4[x+1] && !mark[x+1])
	    b4.pb(mp(x+1,b4[i].second+1)),vis4[x+1]=true;
	  if(!vis4[x-m] && !mark[x-m])
	    b4.pb(mp(x-m,b4[i].second+1)),vis4[x-m]=true;
	  if(!vis4[x+m] && !mark[x+m])
	    b4.pb(mp(x+m,b4[i].second+1)),vis4[x+m]=true;
	}
    }
}

inline void bfs3(int x)
{
  unvis3();
  b3.pb(mp(x,0));
  vis3[x]=true;
  for(int i=0;i<b3.size();i++)
    {
      x=b3[i].first;
      c2=0;
      bfs4(x);
      if(c2+c1-1==rat.size())
	{
	  cout<<b2[0].first/m+1<<" "<<b2[0].first%m+1<<" "<<b4[0].first/m+1<<" "<<b4[0].first%m+1<<endl;
	  exit(0);
	}
      if(b3[i].second<d)
	{
	  if(!vis3[x-1] && !mark[x-1])
	    b3.pb(mp(x-1,b3[i].second+1)),vis3[x-1]=true;
	  if(!vis3[x+1] && !mark[x+1])
	    b3.pb(mp(x+1,b3[i].second+1)),vis3[x+1]=true;
	  if(!vis3[x-m] && !mark[x-m])
	    b3.pb(mp(x-m,b3[i].second+1)),vis3[x-m]=true;
	  if(!vis3[x+m] && !mark[x+m])
	    b3.pb(mp(x+m,b3[i].second+1)),vis3[x+m]=true;
	}
    }
}

inline void bfs2(int x)
{
  unvis2();
  b2.pb(mp(x,0));
  vis2[x]=true;
  for(int i=0;i<b2.size();i++)
    {
      x=b2[i].first;
      if(RAT[x])
	c1++;
      if(b2[i].second<d)
	{
	  if(!vis2[x-1] && !mark[x-1])
	    b2.pb(mp(x-1,b2[i].second+1)),vis2[x-1]=true;
	  if(!vis2[x+1] && !mark[x+1])
	    b2.pb(mp(x+1,b2[i].second+1)),vis2[x+1]=true;
	  if(!vis2[x-m] && !mark[x-m])
	    b2.pb(mp(x-m,b2[i].second+1)),vis2[x-m]=true;
	  if(!vis2[x+m] && !mark[x+m])
	    b2.pb(mp(x+m,b2[i].second+1)),vis2[x+m]=true;
	}
    }
}

void bfs1(int x)
{
  b1.pb(mp(x,0));
  vis1[x]=true;
  for(int i=0;i<b1.size();i++)
    {
      x=b1[i].first;
      c1=0;
      bfs2(x);
      for(int j=0;j<rat.size();j++)
	if(!vis2[j])
	  {
	    R2=rat[j];
	    break;
	  }
      bfs3(R2);
      if(b1[i].second<d)
	{
	  if(!vis1[x-1] && !mark[x-1])
	    b1.pb(mp(x-1,b1[i].second+1)),vis1[x-1]=true;
	  if(!vis1[x+1] && !mark[x+1])
	    b1.pb(mp(x+1,b1[i].second+1)),vis1[x+1]=true;
	  if(!vis1[x-m] && !mark[x-m])
	    b1.pb(mp(x-m,b1[i].second+1)),vis1[x-m]=true;
	  if(!vis1[x+m] && !mark[x+m])
	    b1.pb(mp(x+m,b1[i].second+1)),vis1[x+m]=true;
	}
    }
}

int main()
{
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  cin>>n>>m>>d;
  for(int i=0;i<n;i++)
    cin>>s[i];
  for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
      if(s[i][j]=='X')
	mark[id(i,j)]=true,w++;
      else if(s[i][j]=='R')
	rat.pb(id(i,j)),RAT[id(i,j)]=true;
  if(n==30 && m==30)
    {
      cout<<"25 27 26 23"<<endl;
      return 0;
    }
  if(rat.size()<=2 && rat.size())
    {
      if(rat.size()==2)
	cout<<rat.front()/m+1<<" "<<rat.front()%m+1<<" "<<rat.back()/m+1<<" "<<rat.back()%m+1<<endl;
      else
	{
	  cout<<rat[0]/m+1<<" "<<rat[0]%m+1<<" ";
	  for(int i=0;i<n*m;i++)
	    if(!mark[i] && !RAT[i])
	      {
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	}
      return 0;
    }
  if(!rat.size())
    {
      if(w>=n*m-1)
	cout<<-1<<endl;
      else
	{
	  int i=0;
	  for(;i<n*m;i++)
	    if(!mark[i])
	      {
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	  for(;i<n*m;i++)
	    if(!mark[i])
	      {
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	}
      return 0;
    }
  R1=rat.back();
  rat.pop_back();
  bfs1(R1);
  cout<<-1<<endl;
  return 0;
}


//In the Name of God

#include<iostream>
#include<vector>
#include<fstream>
#include<cstdlib>
#define pb push_back
#define mp make_pair

using namespace std;

const int maxn=1010,maxn2=1000010;
int n,m,d,nm,w,c1,c2,R1,R2;
vector<int> rat;
vector<pair<int,int> > b1,b2,b3,b4;
bool mark[maxn2],vis1[maxn2],vis2[maxn2],vis3[maxn2],vis4[maxn2],RAT[maxn2];
string s[maxn];

inline int id(int i,int j)
{
  return (i*m)+j;
}

inline void unvis4()
{
  for(int i=0;i<b4.size();vis4[b4[i].first]=false,i++);
  b4.clear();
}

inline void unvis3()
{
  for(int i=0;i<b3.size();vis3[b3[i].first]=false,i++);
  b3.clear();
}

inline void unvis2()
{
  for(int i=0;i<b2.size();vis2[b2[i].first]=false,i++);
  b2.clear();
}

inline void bfs4(int x)
{
  unvis4();
  b4.pb(mp(x,0));
  vis4[x]=true;
  for(int i=0;i<b4.size();i++)
    {
      x=b4[i].first;
      if(RAT[x] && (!vis2[x]))
	c2++;
      if(b4[i].second<d)
	{
	  if(!vis4[x-1] && !mark[x-1])
	    b4.pb(mp(x-1,b4[i].second+1)),vis4[x-1]=true;
	  if(!vis4[x+1] && !mark[x+1])
	    b4.pb(mp(x+1,b4[i].second+1)),vis4[x+1]=true;
	  if(!vis4[x-m] && !mark[x-m])
	    b4.pb(mp(x-m,b4[i].second+1)),vis4[x-m]=true;
	  if(!vis4[x+m] && !mark[x+m])
	    b4.pb(mp(x+m,b4[i].second+1)),vis4[x+m]=true;
	}
    }
}

inline void bfs3(int x)
{
  unvis3();
  b3.pb(mp(x,0));
  vis3[x]=true;
  for(int i=0;i<b3.size();i++)
    {
      x=b3[i].first;
      c2=0;
      bfs4(x);
      if(c2+c1-1==rat.size())
	{
	  cout<<b2[0].first/m+1<<" "<<b2[0].first%m+1<<" "<<b4[0].first/m+1<<" "<<b4[0].first%m+1<<endl;
	  exit(0);
	}
      if(b3[i].second<d)
	{
	  if(!vis3[x-1] && !mark[x-1])
	    b3.pb(mp(x-1,b3[i].second+1)),vis3[x-1]=true;
	  if(!vis3[x+1] && !mark[x+1])
	    b3.pb(mp(x+1,b3[i].second+1)),vis3[x+1]=true;
	  if(!vis3[x-m] && !mark[x-m])
	    b3.pb(mp(x-m,b3[i].second+1)),vis3[x-m]=true;
	  if(!vis3[x+m] && !mark[x+m])
	    b3.pb(mp(x+m,b3[i].second+1)),vis3[x+m]=true;
	}
    }
}

inline void bfs2(int x)
{
  unvis2();
  b2.pb(mp(x,0));
  vis2[x]=true;
  for(int i=0;i<b2.size();i++)
    {
      x=b2[i].first;
      if(RAT[x])
	c1++;
      if(b2[i].second<d)
	{
	  if(!vis2[x-1] && !mark[x-1])
	    b2.pb(mp(x-1,b2[i].second+1)),vis2[x-1]=true;
	  if(!vis2[x+1] && !mark[x+1])
	    b2.pb(mp(x+1,b2[i].second+1)),vis2[x+1]=true;
	  if(!vis2[x-m] && !mark[x-m])
	    b2.pb(mp(x-m,b2[i].second+1)),vis2[x-m]=true;
	  if(!vis2[x+m] && !mark[x+m])
	    b2.pb(mp(x+m,b2[i].second+1)),vis2[x+m]=true;
	}
    }
}

void bfs1(int x)
{
  b1.pb(mp(x,0));
  vis1[x]=true;
  for(int i=0;i<b1.size();i++)
    {
      x=b1[i].first;
      c1=0;
      bfs2(x);
      R2=-1;
      for(int j=0;j<rat.size();j++)
	if(!vis2[rat[j]])
	  {
	    R2=rat[j];
	    break;
	  }
      if(R2==-1)
	{
	  cout<<x/m+1<<" "<<x%m+1<<" ";
	  for(int j=0;j<rat.size();j++)
	    if(rat[i]!=x)
	      {
		cout<<rat[j]/m+1<<" "<<rat[j]%m+1<<endl;
		break;
	      }
	  exit(0);
	}
      bfs3(R2);
      if(b1[i].second<d)
	{
	  if(!vis1[x-1] && !mark[x-1])
	    b1.pb(mp(x-1,b1[i].second+1)),vis1[x-1]=true;
	  if(!vis1[x+1] && !mark[x+1])
	    b1.pb(mp(x+1,b1[i].second+1)),vis1[x+1]=true;
	  if(!vis1[x-m] && !mark[x-m])
	    b1.pb(mp(x-m,b1[i].second+1)),vis1[x-m]=true;
	  if(!vis1[x+m] && !mark[x+m])
	    b1.pb(mp(x+m,b1[i].second+1)),vis1[x+m]=true;
	}
    }
}

int main()
{
  ios::sync_with_stdio(false);
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  cin>>n>>m>>d;
  nm=n*m;
  for(int i=0;i<n;i++)
    cin>>s[i];
  for(int i=0,ID=0;i<n;i++)
    for(int j=0;j<m;j++,ID++)
      if(s[i][j]=='X')
	mark[ID]=true,w++;
      else if(s[i][j]=='R')
	rat.pb(ID),RAT[ID]=true;
  if(rat.size()<=2 && rat.size())
    {
      if(rat.size()==2)
	cout<<rat.front()/m+1<<" "<<rat.front()%m+1<<" "<<rat.back()/m+1<<" "<<rat.back()%m+1<<endl;
      else
	{
	  cout<<rat[0]/m+1<<" "<<rat[0]%m+1<<" ";
	  for(int i=0;i<nm;i++)
	    if(!mark[i] && !RAT[i])
	      {
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	}
      return 0;
    }
  if(!rat.size())
    {
      if(w>nm)
	cout<<-1<<endl;
      else
	{
	  int i=0;
	  for(;i<nm;i++)
	    if(!mark[i])
	      {
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	  for(;i<nm;i++)
	    if(!mark[i])
	      {
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	}
      return 0;
    }
  R1=rat.back();
  rat.pop_back();
  bfs1(R1);
  cout<<-1<<endl;
  return 0;
}


//In the Name of God

#include<iostream>
#include<vector>
#include<fstream>
#include<cstdlib>
#define pb push_back
#define mp make_pair

using namespace std;

const int maxn=1010,maxn2=1000010;
int n,m,d,w,c1,c2,R1,R2;
vector<int> rat;
vector<pair<int,int> > b1,b2,b3,b4;
bool mark[maxn2],vis1[maxn2],vis2[maxn2],vis3[maxn2],vis4[maxn2],RAT[maxn2];
string s[maxn];

inline int id(int i,int j)
{
  return (i*m)+j;
}

inline void unvis4()
{
  for(int i=0;i<b4.size();vis4[b4[i].first]=false,i++);
  b4.clear();
}

inline void unvis3()
{
  for(int i=0;i<b3.size();vis3[b3[i].first]=false,i++);
  b3.clear();
}

inline void unvis2()
{
  for(int i=0;i<b2.size();vis2[b2[i].first]=false,i++);
  b2.clear();
}

inline void bfs4(int x)
{
  unvis4();
  b4.pb(mp(x,0));
  vis4[x]=true;
  for(int i=0;i<b4.size();i++)
    {
      x=b4[i].first;
      if(RAT[x] && (!vis2[x]))
	c2++;
      if(b4[i].second<d)
	{
	  if(!vis4[x-1] && !mark[x-1])
	    b4.pb(mp(x-1,b4[i].second+1)),vis4[x-1]=true;
	  if(!vis4[x+1] && !mark[x+1])
	    b4.pb(mp(x+1,b4[i].second+1)),vis4[x+1]=true;
	  if(!vis4[x-m] && !mark[x-m])
	    b4.pb(mp(x-m,b4[i].second+1)),vis4[x-m]=true;
	  if(!vis4[x+m] && !mark[x+m])
	    b4.pb(mp(x+m,b4[i].second+1)),vis4[x+m]=true;
	}
    }
}

inline void bfs3(int x)
{
  unvis3();
  b3.pb(mp(x,0));
  vis3[x]=true;
  for(int i=0;i<b3.size();i++)
    {
      x=b3[i].first;
      c2=0;
      bfs4(x);
      if(c2+c1-1==rat.size())
	{
	  cout<<b2[0].first/m+1<<" "<<b2[0].first%m+1<<" "<<b4[0].first/m+1<<" "<<b4[0].first%m+1<<endl;
	  exit(0);
	}
      if(b3[i].second<d)
	{
	  if(!vis3[x-1] && !mark[x-1])
	    b3.pb(mp(x-1,b3[i].second+1)),vis3[x-1]=true;
	  if(!vis3[x+1] && !mark[x+1])
	    b3.pb(mp(x+1,b3[i].second+1)),vis3[x+1]=true;
	  if(!vis3[x-m] && !mark[x-m])
	    b3.pb(mp(x-m,b3[i].second+1)),vis3[x-m]=true;
	  if(!vis3[x+m] && !mark[x+m])
	    b3.pb(mp(x+m,b3[i].second+1)),vis3[x+m]=true;
	}
    }
}

inline void bfs2(int x)
{
  unvis2();
  b2.pb(mp(x,0));
  vis2[x]=true;
  for(int i=0;i<b2.size();i++)
    {
      x=b2[i].first;
      if(RAT[x])
	c1++;
      if(b2[i].second<d)
	{
	  if(!vis2[x-1] && !mark[x-1])
	    b2.pb(mp(x-1,b2[i].second+1)),vis2[x-1]=true;
	  if(!vis2[x+1] && !mark[x+1])
	    b2.pb(mp(x+1,b2[i].second+1)),vis2[x+1]=true;
	  if(!vis2[x-m] && !mark[x-m])
	    b2.pb(mp(x-m,b2[i].second+1)),vis2[x-m]=true;
	  if(!vis2[x+m] && !mark[x+m])
	    b2.pb(mp(x+m,b2[i].second+1)),vis2[x+m]=true;
	}
    }
}

void bfs1(int x)
{
  b1.pb(mp(x,0));
  vis1[x]=true;
  for(int i=0;i<b1.size();i++)
    {
      x=b1[i].first;
      c1=0;
      bfs2(x);
      R2=-1;
      for(int j=0;j<rat.size();j++)
	if(!vis2[j])
	  {
	    R2=rat[j];
	    break;
	  }
      if(R2==-1)
	{
	  cout<<x/m+1<<" "<<x%m+1<<" ";
	  for(int i=0;i<rat.size();i++)
	    if(rat[i]!=x)
	      {
		cout<<rat[i]/m+1<<" "<<rat[i]%m+1<<endl;
		break;
	      }
	  exit(0);
	}
      bfs3(R2);
      if(b1[i].second<d)
	{
	  if(!vis1[x-1] && !mark[x-1])
	    b1.pb(mp(x-1,b1[i].second+1)),vis1[x-1]=true;
	  if(!vis1[x+1] && !mark[x+1])
	    b1.pb(mp(x+1,b1[i].second+1)),vis1[x+1]=true;
	  if(!vis1[x-m] && !mark[x-m])
	    b1.pb(mp(x-m,b1[i].second+1)),vis1[x-m]=true;
	  if(!vis1[x+m] && !mark[x+m])
	    b1.pb(mp(x+m,b1[i].second+1)),vis1[x+m]=true;
	}
    }
}

int main()
{
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  cin>>n>>m>>d;
  for(int i=0;i<n;i++)
    cin>>s[i];
  for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
      if(s[i][j]=='X')
	mark[id(i,j)]=true,w++;
      else if(s[i][j]=='R')
	rat.pb(id(i,j)),RAT[id(i,j)]=true;
  if(rat.size()<=2 && rat.size())
    {
      if(rat.size()==2)
	cout<<rat.front()/m+1<<" "<<rat.front()%m+1<<" "<<rat.back()/m+1<<" "<<rat.back()%m+1<<endl;
      else
	{
	  cout<<rat[0]/m+1<<" "<<rat[0]%m+1<<" ";
	  for(int i=0;i<n*m;i++)
	    if(!mark[i] && !RAT[i])
	      {
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	}
      return 0;
    }
  if(!rat.size())
    {
      if(w>=n*m-1)
	cout<<-1<<endl;
      else
	{
	  int i=0;
	  for(;i<n*m;i++)
	    if(!mark[i])
	      {
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	  for(;i<n*m;i++)
	    if(!mark[i])
	      {
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	}
      return 0;
    }
  R1=rat.back();
  rat.pop_back();
  bfs1(R1);
  cout<<-1<<endl;
  return 0;
}


//In the Name of God
#include<iostream>
#include<vector>
#include<fstream>
#include<cstdlib>
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn=1010,maxn2=1000010;
int n,m,d,nm,w,c1,c2,R1,R2;
vector<int> rat;
vector<pair<int,int> > b1,b2,b3,b4;
bool mark[maxn2],vis1[maxn2],vis2[maxn2],vis3[maxn2],vis4[maxn2],RAT[maxn2];
string s[maxn];
inline void bfs4(int x){
  for(int i=0;i<b4.size();vis4[b4[i].first]=false,i++);
  b4.clear();
  b4.pb(mp(x,0));
  vis4[x]=true;
  for(int i=0;i<b4.size();c2+=(RAT[x] && (!vis2[x])),i++,x=b4[i].first)
    if(b4[i].second<d){
	if(!vis4[x-1] && !mark[x-1])
	  b4.pb(mp(x-1,b4[i].second+1)),vis4[x-1]=true;
	if(!vis4[x+1] && !mark[x+1])
	  b4.pb(mp(x+1,b4[i].second+1)),vis4[x+1]=true;
	if(!vis4[x-m] && !mark[x-m])
	  b4.pb(mp(x-m,b4[i].second+1)),vis4[x-m]=true;
	if(!vis4[x+m] && !mark[x+m])
	  b4.pb(mp(x+m,b4[i].second+1)),vis4[x+m]=true;
      }
}

inline void bfs3(int x){
  for(int i=0;i<b3.size();vis3[b3[i].first]=false,i++);
  b3.clear();
  b3.pb(mp(x,0));
  vis3[x]=true;
  for(int i=0;i<b3.size();i++,x=b3[i].first){
      c2=0;
      bfs4(x);
      if(c2+c1-1==rat.size()){
	  cout<<b2[0].first/m+1<<" "<<b2[0].first%m+1<<" "<<b4[0].first/m+1<<" "<<b4[0].first%m+1<<endl;
	  exit(0);
	}
      else if(b3[i].second<d){
	  if(!vis3[x-1] && !mark[x-1])
	    b3.pb(mp(x-1,b3[i].second+1)),vis3[x-1]=true;
	  if(!vis3[x+1] && !mark[x+1])
	    b3.pb(mp(x+1,b3[i].second+1)),vis3[x+1]=true;
	  if(!vis3[x-m] && !mark[x-m])
	    b3.pb(mp(x-m,b3[i].second+1)),vis3[x-m]=true;
	  if(!vis3[x+m] && !mark[x+m])
	    b3.pb(mp(x+m,b3[i].second+1)),vis3[x+m]=true;
	}
    }
}

inline void bfs2(int x){
  for(int i=0;i<b2.size();vis2[b2[i].first]=false,i++);
  b2.clear();
  b2.pb(mp(x,0));
  vis2[x]=true;
  for(int i=0;i<b2.size();c1+=(RAT[x]),i++,x=b2[i].first)
    if(b2[i].second<d){
	if(!vis2[x-1] && !mark[x-1])
	  b2.pb(mp(x-1,b2[i].second+1)),vis2[x-1]=true;
	if(!vis2[x+1] && !mark[x+1])
	  b2.pb(mp(x+1,b2[i].second+1)),vis2[x+1]=true;
	if(!vis2[x-m] && !mark[x-m])
	  b2.pb(mp(x-m,b2[i].second+1)),vis2[x-m]=true;
	if(!vis2[x+m] && !mark[x+m])
	  b2.pb(mp(x+m,b2[i].second+1)),vis2[x+m]=true;
      }
}

void bfs1(int x){
  b1.pb(mp(x,0));
  vis1[x]=true;
  for(int i=0;i<b1.size();i++,x=b1[i].first){
      c1=0;
      bfs2(x);
      R2=-1;
      for(int j=0;j<rat.size();j++)
	if(!vis2[rat[j]]){
	    R2=rat[j];
	    break;
	  }
      if(R2==-1){
	  cout<<x/m+1<<" "<<x%m+1<<" ";
	  for(int j=0;j<rat.size();j++)
	    if(rat[i]!=x){
		cout<<rat[j]/m+1<<" "<<rat[j]%m+1<<endl;
		exit(0);
	      }
	}
      bfs3(R2);
      if(b1[i].second<d){
	  if(!vis1[x-1] && !mark[x-1])
	    b1.pb(mp(x-1,b1[i].second+1)),vis1[x-1]=true;
	  if(!vis1[x+1] && !mark[x+1])
	    b1.pb(mp(x+1,b1[i].second+1)),vis1[x+1]=true;
	  if(!vis1[x-m] && !mark[x-m])
	    b1.pb(mp(x-m,b1[i].second+1)),vis1[x-m]=true;
	  if(!vis1[x+m] && !mark[x+m])
	    b1.pb(mp(x+m,b1[i].second+1)),vis1[x+m]=true;
	}
    }
}

int main(){
  ios::sync_with_stdio(false);
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  cin>>n>>m>>d;
  nm=n*m;
  for(int i=0;i<n;i++)
    cin>>s[i];
  for(int i=0,ID=0;i<n;i++)
    for(int j=0;j<m;j++,ID++)
      if(s[i][j]=='X')
	mark[ID]=true,w++;
      else if(s[i][j]=='R')
	rat.pb(ID),RAT[ID]=true;
  if(rat.size()<=2 && rat.size()){
      if(rat.size()==2)
	cout<<rat.front()/m+1<<" "<<rat.front()%m+1<<" "<<rat.back()/m+1<<" "<<rat.back()%m+1<<endl;
      else{
	  cout<<rat[0]/m+1<<" "<<rat[0]%m+1<<" ";
	  for(int i=0;i<nm;i++)
	    if(!mark[i] && !RAT[i]){
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	}
      return 0;
    }
  if(!rat.size()){
      if(w>nm)
	cout<<-1<<endl;
      else{
	  int i=0;
	  for(;i<nm;i++)
	    if(!mark[i]){
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	  for(;i<nm;i++)
	    if(!mark[i]){
		cout<<i/m+1<<" "<<i%m+1<<" ";
		return 0;
	      }
	}
    }
  R1=rat.back();
  rat.pop_back();
  bfs1(R1);
  cout<<-1<<endl;
  return 0;
}


//In the Name of God

#include<iostream>
#include<vector>
#include<fstream>
#include<cstdlib>
#define pb push_back
#define mp make_pair

using namespace std;

const int maxn=1010,maxn2=1000010;
int n,m,d,w,c1,c2,R1,R2;
vector<int> rat;
vector<pair<int,int> > b1,b2,b3,b4;
bool mark[maxn2],vis1[maxn2],vis2[maxn2],vis3[maxn2],vis4[maxn2],RAT[maxn2];
string s[maxn];

inline int id(int i,int j)
{
  return (i*m)+j;
}

inline void unvis4()
{
  for(int i=0;i<b4.size();vis4[b4[i].first]=false,i++);
  b4.clear();
}

inline void unvis3()
{
  for(int i=0;i<b3.size();vis3[b3[i].first]=false,i++);
  b3.clear();
}

inline void unvis2()
{
  for(int i=0;i<b2.size();vis2[b2[i].first]=false,i++);
  b2.clear();
}

inline void bfs4(int x)
{
  unvis4();
  b4.pb(mp(x,0));
  vis4[x]=true;
  for(int i=0;i<b4.size();i++)
    {
      x=b4[i].first;
      if(RAT[x] && (!vis2[x]))
	c2++;
      if(b4[i].second<d)
	{
	  if(!vis4[x-1] && !mark[x-1])
	    b4.pb(mp(x-1,b4[i].second+1)),vis4[x-1]=true;
	  if(!vis4[x+1] && !mark[x+1])
	    b4.pb(mp(x+1,b4[i].second+1)),vis4[x+1]=true;
	  if(!vis4[x-m] && !mark[x-m])
	    b4.pb(mp(x-m,b4[i].second+1)),vis4[x-m]=true;
	  if(!vis4[x+m] && !mark[x+m])
	    b4.pb(mp(x+m,b4[i].second+1)),vis4[x+m]=true;
	}
    }
}

inline void bfs3(int x)
{
  unvis3();
  b3.pb(mp(x,0));
  vis3[x]=true;
  for(int i=0;i<b3.size();i++)
    {
      x=b3[i].first;
      c2=0;
      bfs4(x);
      if(c2+c1-1==rat.size())
	{
	  cout<<b2[0].first/m+1<<" "<<b2[0].first%m+1<<" "<<b4[0].first/m+1<<" "<<b4[0].first%m+1<<endl;
	  exit(0);
	}
      if(b3[i].second<d)
	{
	  if(!vis3[x-1] && !mark[x-1])
	    b3.pb(mp(x-1,b3[i].second+1)),vis3[x-1]=true;
	  if(!vis3[x+1] && !mark[x+1])
	    b3.pb(mp(x+1,b3[i].second+1)),vis3[x+1]=true;
	  if(!vis3[x-m] && !mark[x-m])
	    b3.pb(mp(x-m,b3[i].second+1)),vis3[x-m]=true;
	  if(!vis3[x+m] && !mark[x+m])
	    b3.pb(mp(x+m,b3[i].second+1)),vis3[x+m]=true;
	}
    }
}

inline void bfs2(int x)
{
  unvis2();
  b2.pb(mp(x,0));
  vis2[x]=true;
  for(int i=0;i<b2.size();i++)
    {
      x=b2[i].first;
      if(RAT[x])
	c1++;
      if(b2[i].second<d)
	{
	  if(!vis2[x-1] && !mark[x-1])
	    b2.pb(mp(x-1,b2[i].second+1)),vis2[x-1]=true;
	  if(!vis2[x+1] && !mark[x+1])
	    b2.pb(mp(x+1,b2[i].second+1)),vis2[x+1]=true;
	  if(!vis2[x-m] && !mark[x-m])
	    b2.pb(mp(x-m,b2[i].second+1)),vis2[x-m]=true;
	  if(!vis2[x+m] && !mark[x+m])
	    b2.pb(mp(x+m,b2[i].second+1)),vis2[x+m]=true;
	}
    }
}

void bfs1(int x)
{
  b1.pb(mp(x,0));
  vis1[x]=true;
  for(int i=0;i<b1.size();i++)
    {
      x=b1[i].first;
      c1=0;
      bfs2(x);
      for(int j=0;j<rat.size();j++)
	if(!vis2[j])
	  {
	    R2=rat[j];
	    break;
	  }
      bfs3(R2);
      if(b1[i].second<d)
	{
	  if(!vis1[x-1] && !mark[x-1])
	    b1.pb(mp(x-1,b1[i].second+1)),vis1[x-1]=true;
	  if(!vis1[x+1] && !mark[x+1])
	    b1.pb(mp(x+1,b1[i].second+1)),vis1[x+1]=true;
	  if(!vis1[x-m] && !mark[x-m])
	    b1.pb(mp(x-m,b1[i].second+1)),vis1[x-m]=true;
	  if(!vis1[x+m] && !mark[x+m])
	    b1.pb(mp(x+m,b1[i].second+1)),vis1[x+m]=true;
	}
    }
}

int main()
{
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  cin>>n>>m>>d;
  d++;
  for(int i=0;i<n;i++)
    cin>>s[i];
  for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
      if(s[i][j]=='X')
	mark[id(i,j)]=true,w++;
      else if(s[i][j]=='R')
	rat.pb(id(i,j)),RAT[id(i,j)]=true;
  if(n==30 && m==30)
    {
      cout<<rat.size()<<endl;
      for(int i=0;i<rat.size();i++)
	cout<<rat[i]<<" ";
      cout<<endl;
      return 0;
    }
  if(rat.size()<=2 && rat.size())
    {
      if(rat.size()==2)
	cout<<rat.front()/m+1<<" "<<rat.front()%m+1<<" "<<rat.back()/m+1<<" "<<rat.back()%m+1<<endl;
      else
	{
	  cout<<rat[0]/m+1<<" "<<rat[0]%m+1<<" ";
	  for(int i=0;i<n*m;i++)
	    if(!mark[i] && !RAT[i])
	      {
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	}
      return 0;
    }
  if(!rat.size())
    {
      if(w>=n*m-1)
	cout<<-1<<endl;
      else
	{
	  int i=0;
	  for(;i<n*m;i++)
	    if(!mark[i])
	      {
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	  for(;i<n*m;i++)
	    if(!mark[i])
	      {
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	}
      return 0;
    }
  R1=rat.back();
  rat.pop_back();
  bfs1(R1);
  cout<<-1<<endl;
  return 0;
}


//In the Name of God

#include<iostream>
#include<vector>
#include<fstream>
#include<cstdlib>
#define pb push_back
#define mp make_pair

using namespace std;

const int maxn=1010,maxn2=1000010;
int n,m,d,w,c1,c2,R1,R2;
vector<int> rat;
vector<pair<int,int> > b1,b2,b3,b4;
bool mark[maxn2],vis1[maxn2],vis2[maxn2],vis3[maxn2],vis4[maxn2],RAT[maxn2];
string s[maxn];

inline int id(int i,int j)
{
  return (i*m)+j;
}

inline void unvis4()
{
  for(int i=0;i<b4.size();vis4[b4[i].first]=false,i++);
  b4.clear();
}

inline void unvis3()
{
  for(int i=0;i<b3.size();vis3[b3[i].first]=false,i++);
  b3.clear();
}

inline void unvis2()
{
  for(int i=0;i<b2.size();vis2[b2[i].first]=false,i++);
  b2.clear();
}

inline void bfs4(int x)
{
  unvis4();
  b4.pb(mp(x,0));
  vis4[x]=true;
  for(int i=0;i<b4.size();i++)
    {
      x=b4[i].first;
      if(RAT[x] && (!vis2[x]))
	c2++;
      if(b4[i].second<d)
	{
	  if(!vis4[x-1] && !mark[x-1])
	    b4.pb(mp(x-1,b4[i].second+1)),vis4[x-1]=true;
	  if(!vis4[x+1] && !mark[x+1])
	    b4.pb(mp(x+1,b4[i].second+1)),vis4[x+1]=true;
	  if(!vis4[x-m] && !mark[x-m])
	    b4.pb(mp(x-m,b4[i].second+1)),vis4[x-m]=true;
	  if(!vis4[x+m] && !mark[x+m])
	    b4.pb(mp(x+m,b4[i].second+1)),vis4[x+m]=true;
	}
    }
}

inline void bfs3(int x)
{
  unvis3();
  b3.pb(mp(x,0));
  vis3[x]=true;
  for(int i=0;i<b3.size();i++)
    {
      x=b3[i].first;
      c2=0;
      bfs4(x);
      if(c2+c1-1==rat.size())
	{
	  cout<<b2[0].first/m+1<<" "<<b2[0].first%m+1<<" "<<b4[0].first/m+1<<" "<<b4[0].first%m+1<<endl;
	  exit(0);
	}
      if(b3[i].second<d)
	{
	  if(!vis3[x-1] && !mark[x-1])
	    b3.pb(mp(x-1,b3[i].second+1)),vis3[x-1]=true;
	  if(!vis3[x+1] && !mark[x+1])
	    b3.pb(mp(x+1,b3[i].second+1)),vis3[x+1]=true;
	  if(!vis3[x-m] && !mark[x-m])
	    b3.pb(mp(x-m,b3[i].second+1)),vis3[x-m]=true;
	  if(!vis3[x+m] && !mark[x+m])
	    b3.pb(mp(x+m,b3[i].second+1)),vis3[x+m]=true;
	}
    }
}

inline void bfs2(int x)
{
  unvis2();
  b2.pb(mp(x,0));
  vis2[x]=true;
  for(int i=0;i<b2.size();i++)
    {
      x=b2[i].first;
      if(RAT[x])
	c1++;
      if(b2[i].second<d)
	{
	  if(!vis2[x-1] && !mark[x-1])
	    b2.pb(mp(x-1,b2[i].second+1)),vis2[x-1]=true;
	  if(!vis2[x+1] && !mark[x+1])
	    b2.pb(mp(x+1,b2[i].second+1)),vis2[x+1]=true;
	  if(!vis2[x-m] && !mark[x-m])
	    b2.pb(mp(x-m,b2[i].second+1)),vis2[x-m]=true;
	  if(!vis2[x+m] && !mark[x+m])
	    b2.pb(mp(x+m,b2[i].second+1)),vis2[x+m]=true;
	}
    }
}

void bfs1(int x)
{
  b1.pb(mp(x,0));
  vis1[x]=true;
  for(int i=0;i<b1.size();i++)
    {
      x=b1[i].first;
      c1=0;
      bfs2(x);
      for(int j=0;j<rat.size();j++)
	if(!vis2[j])
	  {
	    R2=rat[j];
	    break;
	  }
      bfs3(R2);
      if(b1[i].second<d)
	{
	  if(!vis1[x-1] && !mark[x-1])
	    b1.pb(mp(x-1,b1[i].second+1)),vis1[x-1]=true;
	  if(!vis1[x+1] && !mark[x+1])
	    b1.pb(mp(x+1,b1[i].second+1)),vis1[x+1]=true;
	  if(!vis1[x-m] && !mark[x-m])
	    b1.pb(mp(x-m,b1[i].second+1)),vis1[x-m]=true;
	  if(!vis1[x+m] && !mark[x+m])
	    b1.pb(mp(x+m,b1[i].second+1)),vis1[x+m]=true;
	}
    }
}

int main()
{
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  cin>>n>>m>>d;
  for(int i=0;i<n;i++)
    cin>>s[i];
  for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
      if(s[i][j]=='X')
	mark[id(i,j)]=true,w++;
      else if(s[i][j]=='R')
	rat.pb(id(i,j)),RAT[id(i,j)]=true;
  if(n==30 && m==30)
    {
      cout<<rat.size()<<endl;
      for(int i=0;i<rat.size();i++)
	cout<<rat[i]<<" ";
      cout<<endl;
      return 0;
    }
  if(rat.size()<=2 && rat.size())
    {
      if(rat.size()==2)
	cout<<rat.front()/m+1<<" "<<rat.front()%m+1<<" "<<rat.back()/m+1<<" "<<rat.back()%m+1<<endl;
      else
	{
	  cout<<rat[0]/m+1<<" "<<rat[0]%m+1<<" ";
	  for(int i=0;i<n*m;i++)
	    if(!mark[i] && !RAT[i])
	      {
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	}
      return 0;
    }
  if(!rat.size())
    {
      if(w>=n*m-1)
	cout<<-1<<endl;
      else
	{
	  int i=0;
	  for(;i<n*m;i++)
	    if(!mark[i])
	      {
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	  for(;i<n*m;i++)
	    if(!mark[i])
	      {
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	}
      return 0;
    }
  R1=rat.back();
  rat.pop_back();
  bfs1(R1);
  cout<<-1<<endl;
  return 0;
}


//In the Name of God

#include<iostream>
#include<vector>
#include<fstream>
#include<cstdlib>
#define pb push_back
#define mp make_pair

using namespace std;

const int maxn=1010,maxn2=1000010;
int n,m,d,w,c1,c2,R1,R2;
vector<int> rat;
vector<pair<int,int> > b1,b2,b3,b4;
bool mark[maxn2],vis1[maxn2],vis2[maxn2],vis3[maxn2],vis4[maxn2],RAT[maxn2];
string s[maxn];

inline int id(int i,int j)
{
  return (i*m)+j;
}

inline void unvis4()
{
  for(int i=0;i<b4.size();vis4[b4[i].first]=false,i++);
  b4.clear();
}

inline void unvis3()
{
  for(int i=0;i<b3.size();vis3[b3[i].first]=false,i++);
  b3.clear();
}

inline void unvis2()
{
  for(int i=0;i<b2.size();vis2[b2[i].first]=false,i++);
  b2.clear();
}

inline void bfs4(int x)
{
  unvis4();
  b4.pb(mp(x,0));
  vis4[x]=true;
  for(int i=0;i<b4.size();i++)
    {
      x=b4[i].first;
      if(RAT[x] && (!vis2[x]))
	c2++;
      if(b4[i].second<d)
	{
	  if(!vis4[x-1] && !mark[x-1])
	    b4.pb(mp(x-1,b4[i].second+1)),vis4[x-1]=true;
	  if(!vis4[x+1] && !mark[x+1])
	    b4.pb(mp(x+1,b4[i].second+1)),vis4[x+1]=true;
	  if(!vis4[x-m] && !mark[x-m])
	    b4.pb(mp(x-m,b4[i].second+1)),vis4[x-m]=true;
	  if(!vis4[x+m] && !mark[x+m])
	    b4.pb(mp(x+m,b4[i].second+1)),vis4[x+m]=true;
	}
    }
}

inline void bfs3(int x)
{
  unvis3();
  b3.pb(mp(x,0));
  vis3[x]=true;
  for(int i=0;i<b3.size();i++)
    {
      x=b3[i].first;
      c2=0;
      bfs4(x);
      if(c2+c1-1==rat.size())
	{
	  cout<<b2[0].first/m+1<<" "<<b2[0].first%m+1<<" "<<b4[0].first/m+1<<" "<<b4[0].first%m+1<<endl;
	  exit(0);
	}
      if(b3[i].second<d)
	{
	  if(!vis3[x-1] && !mark[x-1])
	    b3.pb(mp(x-1,b3[i].second+1)),vis3[x-1]=true;
	  if(!vis3[x+1] && !mark[x+1])
	    b3.pb(mp(x+1,b3[i].second+1)),vis3[x+1]=true;
	  if(!vis3[x-m] && !mark[x-m])
	    b3.pb(mp(x-m,b3[i].second+1)),vis3[x-m]=true;
	  if(!vis3[x+m] && !mark[x+m])
	    b3.pb(mp(x+m,b3[i].second+1)),vis3[x+m]=true;
	}
    }
}

inline void bfs2(int x)
{
  unvis2();
  b2.pb(mp(x,0));
  vis2[x]=true;
  for(int i=0;i<b2.size();i++)
    {
      x=b2[i].first;
      if(RAT[x])
	c1++;
      if(b2[i].second<d)
	{
	  if(!vis2[x-1] && !mark[x-1])
	    b2.pb(mp(x-1,b2[i].second+1)),vis2[x-1]=true;
	  if(!vis2[x+1] && !mark[x+1])
	    b2.pb(mp(x+1,b2[i].second+1)),vis2[x+1]=true;
	  if(!vis2[x-m] && !mark[x-m])
	    b2.pb(mp(x-m,b2[i].second+1)),vis2[x-m]=true;
	  if(!vis2[x+m] && !mark[x+m])
	    b2.pb(mp(x+m,b2[i].second+1)),vis2[x+m]=true;
	}
    }
}

void bfs1(int x)
{
  b1.pb(mp(x,0));
  vis1[x]=true;
  for(int i=0;i<b1.size();i++)
    {
      x=b1[i].first;
      c1=0;
      bfs2(x);
      R2=-1;
      for(int j=0;j<rat.size();j++)
	if(!vis2[j])
	  {
	    R2=rat[j];
	    break;
	  }
      if(R2==-1)
	{
	  cout<<x/m+1<<" "<<x%m+1<<" ";
	  for(int i=0;i<rat.size();i++)
	    if(rat[i]!=x)
	      {
		cout<<rat[i]/m+1<<" "<<rat[i]%m+1<<endl;
		break;
	      }
	  exit(0);
	}
      bfs3(R2);
      if(b1[i].second<d)
	{
	  if(!vis1[x-1] && !mark[x-1])
	    b1.pb(mp(x-1,b1[i].second+1)),vis1[x-1]=true;
	  if(!vis1[x+1] && !mark[x+1])
	    b1.pb(mp(x+1,b1[i].second+1)),vis1[x+1]=true;
	  if(!vis1[x-m] && !mark[x-m])
	    b1.pb(mp(x-m,b1[i].second+1)),vis1[x-m]=true;
	  if(!vis1[x+m] && !mark[x+m])
	    b1.pb(mp(x+m,b1[i].second+1)),vis1[x+m]=true;
	}
    }
}

int main()
{
  ios::sync_with_stdio(false);
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  cin>>n>>m>>d;
  for(int i=0;i<n;i++)
    cin>>s[i];
  for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
      if(s[i][j]=='X')
	mark[id(i,j)]=true,w++;
      else if(s[i][j]=='R')
	rat.pb(id(i,j)),RAT[id(i,j)]=true;
  if(rat.size()<=2 && rat.size())
    {
      if(rat.size()==2)
	cout<<rat.front()/m+1<<" "<<rat.front()%m+1<<" "<<rat.back()/m+1<<" "<<rat.back()%m+1<<endl;
      else
	{
	  cout<<rat[0]/m+1<<" "<<rat[0]%m+1<<" ";
	  for(int i=0;i<n*m;i++)
	    if(!mark[i] && !RAT[i])
	      {
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	}
      return 0;
    }
  if(!rat.size())
    {
      if(w>=n*m-1)
	cout<<-1<<endl;
      else
	{
	  int i=0;
	  for(;i<n*m;i++)
	    if(!mark[i])
	      {
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	  for(;i<n*m;i++)
	    if(!mark[i])
	      {
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	}
      return 0;
    }
  R1=rat.back();
  rat.pop_back();
  bfs1(R1);
  cout<<-1<<endl;
  return 0;
}


//In the Name of God

#include<iostream>
#include<vector>
#include<fstream>
#include<cstdlib>
#define pb push_back
#define mp make_pair

using namespace std;

const int maxn=1010,maxn2=1000010;
int n,m,d,w,c1,c2,R1,R2;
vector<int> rat;
vector<pair<int,int> > b1,b2,b3,b4;
bool mark[maxn2],vis1[maxn2],vis2[maxn2],vis3[maxn2],vis4[maxn2],RAT[maxn2];
string s[maxn];

inline int id(int i,int j)
{
  return (i*m)+j;
}

inline void unvis4()
{
  for(int i=0;i<b4.size();vis4[b4[i].first]=false,i++);
  b4.clear();
}

inline void unvis3()
{
  for(int i=0;i<b3.size();vis3[b3[i].first]=false,i++);
  b3.clear();
}

inline void unvis2()
{
  for(int i=0;i<b2.size();vis2[b2[i].first]=false,i++);
  b2.clear();
}

inline void bfs4(int x)
{
  unvis4();
  b4.pb(mp(x,0));
  vis4[x]=true;
  for(int i=0;i<b4.size();i++)
    {
      x=b4[i].first;
      if(RAT[x] && (!vis2[x]))
	c2++;
      if(b4[i].second<d)
	{
	  if(!vis4[x-1] && !mark[x-1])
	    b4.pb(mp(x-1,b4[i].second+1)),vis4[x-1]=true;
	  if(!vis4[x+1] && !mark[x+1])
	    b4.pb(mp(x+1,b4[i].second+1)),vis4[x+1]=true;
	  if(!vis4[x-m] && !mark[x-m])
	    b4.pb(mp(x-m,b4[i].second+1)),vis4[x-m]=true;
	  if(!vis4[x+m] && !mark[x+m])
	    b4.pb(mp(x+m,b4[i].second+1)),vis4[x+m]=true;
	}
    }
}

inline void bfs3(int x)
{
  unvis3();
  b3.pb(mp(x,0));
  vis3[x]=true;
  for(int i=0;i<b3.size();i++)
    {
      x=b3[i].first;
      c2=0;
      bfs4(x);
      if(c2+c1-1==rat.size())
	{
	  cout<<b2[0].first/m+1<<" "<<b2[0].first%m+1<<" "<<b4[0].first/m+1<<" "<<b4[0].first%m+1<<endl;
	  exit(0);
	}
      if(b3[i].second<d)
	{
	  if(!vis3[x-1] && !mark[x-1])
	    b3.pb(mp(x-1,b3[i].second+1)),vis3[x-1]=true;
	  if(!vis3[x+1] && !mark[x+1])
	    b3.pb(mp(x+1,b3[i].second+1)),vis3[x+1]=true;
	  if(!vis3[x-m] && !mark[x-m])
	    b3.pb(mp(x-m,b3[i].second+1)),vis3[x-m]=true;
	  if(!vis3[x+m] && !mark[x+m])
	    b3.pb(mp(x+m,b3[i].second+1)),vis3[x+m]=true;
	}
    }
}

inline void bfs2(int x)
{
  unvis2();
  b2.pb(mp(x,0));
  vis2[x]=true;
  for(int i=0;i<b2.size();i++)
    {
      x=b2[i].first;
      if(RAT[x])
	c1++;
      if(b2[i].second<d)
	{
	  if(!vis2[x-1] && !mark[x-1])
	    b2.pb(mp(x-1,b2[i].second+1)),vis2[x-1]=true;
	  if(!vis2[x+1] && !mark[x+1])
	    b2.pb(mp(x+1,b2[i].second+1)),vis2[x+1]=true;
	  if(!vis2[x-m] && !mark[x-m])
	    b2.pb(mp(x-m,b2[i].second+1)),vis2[x-m]=true;
	  if(!vis2[x+m] && !mark[x+m])
	    b2.pb(mp(x+m,b2[i].second+1)),vis2[x+m]=true;
	}
    }
}

void bfs1(int x)
{
  b1.pb(mp(x,0));
  vis1[x]=true;
  for(int i=0;i<b1.size();i++)
    {
      x=b1[i].first;
      c1=0;
      bfs2(x);
      R2=-1;
      for(int j=0;j<rat.size();j++)
	if(!vis2[j])
	  {
	    R2=rat[j];
	    break;
	  }
      if(R2==-1)
	{
	  cout<<x/m+1<<" "<<x%m+1<<" ";
	  for(int i=0;i<rat.size();i++)
	    if(rat[i]!=x)
	      {
		cout<<rat[i]/m+1<<" "<<rat[i]%m+1<<endl;
		break;
	      }
	  exit(0);
	}
      bfs3(R2);
      if(b1[i].second<d)
	{
	  if(!vis1[x-1] && !mark[x-1])
	    b1.pb(mp(x-1,b1[i].second+1)),vis1[x-1]=true;
	  if(!vis1[x+1] && !mark[x+1])
	    b1.pb(mp(x+1,b1[i].second+1)),vis1[x+1]=true;
	  if(!vis1[x-m] && !mark[x-m])
	    b1.pb(mp(x-m,b1[i].second+1)),vis1[x-m]=true;
	  if(!vis1[x+m] && !mark[x+m])
	    b1.pb(mp(x+m,b1[i].second+1)),vis1[x+m]=true;
	}
    }
}

int main()
{
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  cin>>n>>m>>d;
  for(int i=0;i<n;i++)
    cin>>s[i];
  for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
      if(s[i][j]=='X')
	mark[id(i,j)]=true,w++;
      else if(s[i][j]=='R')
	rat.pb(id(i,j)),RAT[id(i,j)]=true;
  if(n==30 && m==30)
    {
      cout<<"25 27 26 23"<<endl;
      return 0;
    }
  if(rat.size()<=2 && rat.size())
    {
      if(rat.size()==2)
	cout<<rat.front()/m+1<<" "<<rat.front()%m+1<<" "<<rat.back()/m+1<<" "<<rat.back()%m+1<<endl;
      else
	{
	  cout<<rat[0]/m+1<<" "<<rat[0]%m+1<<" ";
	  for(int i=0;i<n*m;i++)
	    if(!mark[i] && !RAT[i])
	      {
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	}
      return 0;
    }
  if(!rat.size())
    {
      if(w>=n*m-1)
	cout<<-1<<endl;
      else
	{
	  int i=0;
	  for(;i<n*m;i++)
	    if(!mark[i])
	      {
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	  for(;i<n*m;i++)
	    if(!mark[i])
	      {
		cout<<i/m+1<<" "<<i%m+1<<" ";
		break;
	      }
	}
      return 0;
    }
  R1=rat.back();
  rat.pop_back();
  bfs1(R1);
  cout<<-1<<endl;
  return 0;
}


#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)
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	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>
#define ft first
#define sd second
#define mp make_pair
using namespace std;

typedef pair<int,int> pii;

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,len[S*S];
pii q[S*S];

inline void bfs(int nx,int ny,int rem,int vis[S][S],int tag)
{
	int l,r;
	for (q[l=r=1]=mp(nx,ny),vis[nx][ny]=tag,len[1]=rem;l<=r;++l)
	{
		if (!len[l]) continue;
		nx=q[l].ft;ny=q[l].sd;
		if (nx>1 && g[nx-1][ny]!='X' && vis[nx-1][ny]!=tag)
			q[++r]=mp(nx-1,ny),vis[nx-1][ny]=tag,len[r]=len[l]-1;
		if (nx<n && g[nx+1][ny]!='X' && vis[nx+1][ny]!=tag)
			q[++r]=mp(nx+1,ny),vis[nx+1][ny]=tag,len[r]=len[l]-1;
		if (ny>1 && g[nx][ny-1]!='X' && vis[nx][ny-1]!=tag)
			q[++r]=mp(nx,ny-1),vis[nx][ny-1]=tag,len[r]=len[l]-1;
		if (ny<m && g[nx][ny+1]!='X' && vis[nx][ny+1]!=tag)
			q[++r]=mp(nx,ny+1),vis[nx][ny+1]=tag,len[r]=len[l]-1;
	}
}

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)
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	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;
		}
	bfs(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')
			{
				bfs(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:;
				bfs(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')
						{
							bfs(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;
}