import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class prog {

    private static int[] X_POS = new int[] { -1, 1, 0, 0 };
    private static int[] Y_POS = new int[] { 0, 0, -1, 1 };
    private static int currentFill = 1;
    private static int[][] fill;
    private static int[][] field;
    private static int m;
    private static int n;

    public static void main(String[] args) throws java.lang.Exception {
        Scanner scanner = new Scanner(System.in);
        Integer type = Integer.parseInt(scanner.nextLine());
        String[] data = scanner.nextLine().split(" ");

        m = Integer.parseInt(data[0]);
        n = Integer.parseInt(data[1]);

        field = new int[m + 2][n + 2];
        fill = new int[m + 2][n + 2];

        for (int i = 0; i < m; i++) {
            String cells = scanner.nextLine();
            for (int j = 1; j <= n; j++) {
                field[i + 1][j] = cells.charAt(j - 1);
            }
        }

        int max = 0;
        int xMax = 0;
        int yMax = 0;
        int cMax = 0;
        for (int i = 1; i <= m; i++) {
            for (int j = 1; j <= n; j++) {
                int size = calcSize(i, j, field[i][j]);
                if (size > max) {
                    max = size;
                    xMax = i;
                    yMax = j;
                    cMax = field[i][j];
                }
                if (type == 2) {
                    for (int k = 0; k < 4; k++) {
                        int x = i + X_POS[k];
                        int y = j + Y_POS[k];
                        if (field[x][y] != 0 && field[i][j] != field[x][y]) {
                            size = calcSize(i, j, field[x][y]);
                            currentFill++;
                            if (size > max) {
                                max = size;
                                xMax = i;
                                yMax = j;
                                cMax = field[x][y];
                            }
                        }
                    }
                }
            }
        }

        if (type == 1) {
            System.out.println(max);
        } else {
            System.out.println(xMax + " " + yMax);
            System.out.println((char) cMax);
        }
        scanner.close();
    }

    private static int calcSize(int x, int y, int c) {
        int res = 1;
        Set<Integer> toFill = new HashSet<Integer>();
        toFill.add((x - 1) * n + y - 1);
        while (!toFill.isEmpty()) {
            Integer elem = toFill.iterator().next();
            toFill.remove(elem);
            x = elem / n + 1;
            y = elem % n + 1;
            fill[x][y] = currentFill;
            for (int i = 0; i < 4; i++) {
                int x1 = x + X_POS[i];
                int y1 = y + Y_POS[i];
                if (c == field[x1][y1] && field[x1][y1] != 0 && fill[x1][y1] < currentFill) {
                    int e = (x1 - 1) * n + y1 - 1;
                    toFill.add(e);
                    res++;
                }
            }
        }
        return res;
    }
}