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

/**
 * Created by roi on 05.04.2016.
 */
public class Task2 {

    int n, m;
    boolean g;
    char[][] field;

    void solve(IO io) {
        n = io.nextInt();
        m = io.nextInt();
        g = io.nextInt() == 1;

        time = new long[n][m];
        cycle = new int[n][m];
        visited = new boolean[n][m];

        field = new char[n][m];
        for (int i = 0; i < n; i++) {
            field[i] = io.readLine().toCharArray();
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (!visited[i][j]) {
                    go(i, j);
                    curCycle++;

                    startTime = timer;
                    timer++;
                }
            }
        }


        for (int i = 0; i < n; i++) {
            Arrays.fill(visited[i], false);
        }


        if (!g) {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    int cc = cycle[i][j];
                    if (cc != 0 && cnt[cc] == 0) {
                        curCan.clear();
                        cnt[cc] = canGetRev(i, j, 0);
                    }
                }
            }

            int ans = 0;
            for (int i = 0; i < len.length; i++) {
                ans += Math.min(len[i], cnt[i]);
            }
            io.println(ans);
        } else {



            long ans = 0;

            StringBuilder builder = new StringBuilder();
            timer = 100;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    int cc = cycle[i][j];
                    if (cc != 0 && cnt[cc] == 0) {
                        curCan.clear();
                        cnt[cc] = canGetRev(i, j, 0);

                        long avail = Math.min(len[cc], cnt[cc]);
                        for (Robot r : curCan) {
                            if (avail == 0)
                                break;

                            long prev = timer;
                            while (timer - r.dist <= prev) {
                                timer += len[cc];
                            }

                            if (timer >= 1000000000) {
                                throw new AssertionError();
                            }

                            ans++;
                            builder.append(r.x + 1).append(' ').append(r.y + 1).append(' ').append(timer - r.dist).append('\n');
                            avail--;

                            timer += len[cc] - 1;
                        }
                    }
                }
            }

            io.println(ans);
            io.println(builder.toString());

            throw new AssertionError();

        }
    }

    long[][] time;
    boolean[][] visited;
    long timer = 1;

    long[] len = new long[1000000];
    long[] cnt = new long[1000000];

    int[][] cycle;
    int curCycle = 1;


    TreeSet<Robot> curCan = new TreeSet<>(new Comparator<Robot>() {
        @Override
        public int compare(Robot o1, Robot o2) {
            if (o1.dist == o2.dist) {
                return Integer.compare(o1.hashCode(), o2.hashCode());
            }
            return Integer.compare(o1.dist, o2.dist);
        }
    });

    int canGetRev(int i, int j, int dist) {
        if (visited[i][j])
            return 0;
        visited[i][j] = true;

        int res = 0;
        if (isRobot(i, j)) {
            res++;
            if (g) curCan.add(new Robot(i, j, dist));
        }

        for (int k = 0; k < 4; k++) {
            if (isValid(i + di[k], j + dj[k]) &&
                    moveI(i + di[k], field[i + di[k]][j + dj[k]]) == i &&
                    moveJ(j + dj[k], field[i + di[k]][j + dj[k]]) == j) {
                res += canGetRev(i + di[k], j + dj[k], dist + 1);
            }
        }

        return res;
    }

    final int[] di = {1, 0, 0, -1};
    final int[] dj = {0, 1, -1, 0};


    long startTime = 0;

    long go(int i, int j) { // returns time after which cycle = true
        if (time[i][j] > startTime) {
            cycle[i][j] = curCycle;
            len[curCycle] = timer - time[i][j];
            return time[i][j];
        }

        if (visited[i][j]) return Long.MAX_VALUE;
        visited[i][j] = true;

        time[i][j] = timer++;
        char move = field[i][j];
        int ni = moveI(i, move);
        int nj = moveJ(j, move);

        if (cycle[ni][nj] != 0) {
            int idx = cycle[ni][nj];
            return Integer.MAX_VALUE;
        }

        long t = go(ni, nj);
        if (time[i][j] >= t) {
            cycle[i][j] = curCycle;
        }
        return t;
    }

    int moveI(int i, char move) {
        move = Character.toUpperCase(move);
        if (move == 'N') return i - 1;
        if (move == 'S') return i + 1;
        return i;
    }

    int moveJ(int j, char move) {
        move = Character.toUpperCase(move);
        if (move == 'W') return j - 1;
        if (move == 'E') return j + 1;
        return j;
    }

    int revI(int i, char move) {
        move = Character.toUpperCase(move);
        if (move == 'N') return i + 1;
        if (move == 'S') return i - 1;
        return i;
    }

    int revJ(int j, char move) {
        move = Character.toUpperCase(move);
        if (move == 'W') return j + 1;
        if (move == 'E') return j - 1;
        return j;
    }

    boolean isValid(int i, int j) {
        return 0 <= i && 0 <= j && i < n && j < m;
    }


    boolean isRobot(int i, int j) {
        return field[i][j] == Character.toUpperCase(field[i][j]);
    }

    class Robot {
        int x, y;
        int dist;

        int fx, fy;

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

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

        public Robot(int x, int y, int dist, int fx, int fy) {
            this.x = x;
            this.y = y;
            this.dist = dist;
            this.fx = fx;
            this.fy = fy;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            Robot robot = (Robot) o;

            if (x != robot.x) return false;
            return y == robot.y;

        }

        @Override
        public int hashCode() {
            int result = x;
            result = 31 * result + y;
            return result;
        }
    }


    public static void main(String[] args) {
        Task2 solver = new Task2();
        IO io = new IO("robots");
        solver.solve(io);
        io.out.close();
    }

    static class IO {
        BufferedReader in;
        StringTokenizer tok;
        PrintWriter out;

        IO(String file) {
            try {
                in = new BufferedReader(new FileReader(file + ".in"));
                out = new PrintWriter(file + ".out");
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        String readLine() {
            try {
                return in.readLine();
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            }
        }

        String nextToken() {
            if (tok == null || !tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                    return null;
                }
            }
            return tok.nextToken();
        }

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

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

        int[] readIntArray(int len) {
            int[] res = new int[len];
            for (int i = 0; i < len; i++) {
                res[i] = nextInt();
            }
            return res;
        }

        void println(long x) {
            out.println(x);
        }

        void println(String s) {
            out.println(s);
        }
    }

}