#include <iostream>
#include <fstream>
#include <string>
#include <bitset>
#include <deque>
#define M 405
using namespace std;
fstream fin("ferma3.in",ios::in),fout("ferma3.out",ios::out);
int di[]={-1,0,1,0},dj[]={0,1,0,-1};
deque <pair<int,int> > d;
int cost[M*M],who[M][M];
bitset <M> bit[M];
string s[M];
int n,m,t,ir,jr;
char color;

void citire(){
    cin>>t>>n>>m;
    for(int i=0;i<n;i++) cin>>s[i];
}
bool ok(int i,int j){
    if(-1<i&&i<n&&-1<j&&j<m) return 1;
    return 0;
}

int bfs(int i,int j,int nr){
    int cate=1;
    bit[i][j]=1;
    d.clear();
    d.push_back(make_pair(i,j));
    while(!d.empty()){
        i=d.front().first;
        j=d.front().second;
        who[i][j]=nr;
        for(int k=0;k<4;k++){
            if(ok(i+di[k],j+dj[k])==1&&s[i+di[k]][j+dj[k]]==s[i][j]&&bit[i+di[k]][j+dj[k]]==0){
                bit[i+di[k]][j+dj[k]]=1;
                cate++;
                d.push_back(make_pair(i+di[k],j+dj[k]));
            }
        }
        d.pop_front();
    }
    return cate;
}
int solv(){
    int actual,maxim=-999,r,nr=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(bit[i][j]==0)
            {
                nr++;
                actual=bfs(i,j,nr);
                cost[nr]=actual;
                maxim=max(maxim,actual);
            }
        }
    }
    return maxim;
}
void cauta(int a,int b,int&maxim)
{
    int i,j,c,d,e,f;
    for(i=0;i<4;i++)
    {
        for(j=0;j<4;j++)
        {
            c=a+di[i];d=b+dj[i];
            e=a+di[j];f=b+dj[j];
            if(ok(c,d)==1&&ok(e,f)==1&&s[c][d]==s[e][f]&&s[c][d]!=s[a][b])
            {
                if(who[c][d]==who[e][f])
                {
                    if(cost[who[c][d]]+1>=maxim)
                    {
                        color=s[c][d];
                        ir=a;
                        jr=b;
                        maxim=cost[who[c][d]]+1;
                    }
                }
                else
                {
                    if(cost[who[c][d]]+cost[who[e][f]]+1>=maxim)
                    {
                        color=s[c][d];
                        ir=a;
                        jr=b;
                        maxim=cost[who[c][d]]+cost[who[e][f]]+1;
                    }
                }
            }
        }
    }
}
int search()
{
    int maxim=-9999,r;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cauta(i,j,maxim);
        }
    }
    //cauta(230,42,maxim);
    //cauta(243,1,maxim);
    cout<<ir+1<<" "<<jr+1<<"\n"<<color<<"\n";
    fout<<ir+1<<" "<<jr+1<<"\n"<<color<<"\n";
}
int main(){
    int a;
    citire();
    a=solv();
    if(t==1) fout<<a<<"\n";
    else
        search();
    return 0;
}