import java.io.*;
import java.util.*;

public class Robots {
    String fileName = "robots";

    ArrayList<Cycle> cycles;
    int n, m, num = 0;
    char[][] table;
    int[][] number, dist;

    public void solve() throws IOException {
        n = nextInt();
        m = nextInt();
        int g = nextInt();
        table = new char[n + 1][m + 1];
        HashSet<Robot> robots = new HashSet<>();

        int u = 0;
        for (int i = 0; i < n; i++) {
            char[] str = br.readLine().toCharArray();
            for (int j = 0; j < m; j++) {
                if (str[j] < 'Z') {
                    table[i][j] = (char) (str[j] + 'a' - 'A');
                    robots.add(new Robot(u, i, j));
                    u++;
                } else {
                    table[i][j] = str[j];
                }
            }
        }

        cycles = new ArrayList<>();
        visited = new boolean[n * m];
        number = new int[n][m];
        dist = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (!visited[i * m + j]) {
                    length = 0;
                    vis = new HashMap<>();
                    dfs(i, j);
                }
            }
        }

        Cycle[] c = new Cycle[cycles.size()];
        for (Cycle cycle : cycles) {
            c[cycle.num] = cycle;
        }

        int result = 0;
        for (Robot robot : robots) {
            int t = number[robot.x][robot.y];
            if (t == -1) {
                continue;
            }
            robot.cycle = t;
            robot.dist = dist[robot.x][robot.y];
            c[t].robots.add(robot);
            if (c[t].robots.size() <= c[t].length) {
                result++;
            }
        }

        out.println(result);
        if (g == 1) {
            for (Cycle cycle : c) {
                int t = 0;
                for (Robot r : cycle.robots) {
                    if (cycle.rest > 0) {
                        cycle.rest--;
                        int tnew = (((t + 1 - r.dist) % cycle.length) + cycle.length) % cycle.length;
                        out.println((r.x + 1) + " " + (r.y + 1) + " " + (tnew + 1));
                        t++;
                    } else {
                        break;
                    }
                }
            }
        }
    }

    boolean[] visited;
    HashMap<Integer, Integer> vis;
    int length;

    private int dfs(int x, int y) {
        if (x < 0 || y < 0 || x >= n || y >= m) {
            return -1;
        }
        int v = x * m + y;
        if (visited[v]) {
            if (vis.containsKey(v)) {
                cycles.add(new Cycle(num, vis.size() - vis.get(v), x, y));
                number[x][y] = num;
                num++;
                return num - 1;
            } else {
                return number[x][y];
            }
        } else {
            visited[v] = true;
            vis.put(v, length);
            length++;
            switch (table[x][y]) {
                case 'w':
                    number[x][y] = dfs(x, y - 1);
                    if (number[x][y] != -1) {
                        dist[x][y] = dist[x][y - 1] + 1;
                    }
                    break;
                case 'e':
                    number[x][y] = dfs(x, y + 1);
                    if (number[x][y] != -1) {
                        dist[x][y] = dist[x][y + 1] + 1;
                    }
                    break;
                case 'n':
                    number[x][y] = dfs(x - 1, y);
                    if (number[x][y] != -1) {
                        dist[x][y] = dist[x - 1][y] + 1;
                    }
                    break;
                case 's':
                    number[x][y] = dfs(x + 1, y);
                    if (number[x][y] != -1) {
                        dist[x][y] = dist[x + 1][y] + 1;
                    }
            }
            vis.remove(v);
            return number[x][y];
        }
    }

    private class Cycle {
        int num, length, x, y, rest;
        ArrayList<Robot> robots;

        public Cycle(int num, int length, int x, int y) {
            this.num = num;
            this.length = length;
            rest = length;
            this.x = x;
            this.y = y;
            robots = new ArrayList<>();
        }
    }

    private class Robot {
        int num, x, y;
        int cycle, dist;

        public Robot(int num, int x, int y) {
            this.num = num;
            this.x = x;
            this.y = y;
        }
    }

    public void run() {
        try {
            br = new BufferedReader(new FileReader(fileName + ".in"));
            out = new PrintWriter(fileName + ".out");

            solve();

            out.close();
        } catch (Exception e) {
            System.exit(0);
        }
    }

    BufferedReader br;
    StringTokenizer in;
    PrintWriter out;

    public String nextToken() throws IOException {
        while (in == null || !in.hasMoreTokens()) {
            in = new StringTokenizer(br.readLine());
        }
        return in.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    public static void main(String[] args) {
        new Robots().run();
    }

}