/**
 * Created by roi on 05.04.2016.
 */
import java.io.*;
import java.util.*;

public class B {
    String fileName = "robots";
    int[][] mo;
    int[] z = new int[2];
    int x;
    int y;
    int[] func(int[] u){
        x = u[0];
        y = u[1];
        if (mo[x][y] == 0){
            z[0] = x - 1;
            z[1] = y;
        }
        if (mo[x][y] == 1){
            z[0] = x;
            z[1] = y + 1;
        }
        if (mo[x][y] == 2){
            z[0] = x + 1;
            z[1] = y;
        }
        if (mo[x][y] == 3){
            z[0] = x;
            z[1] = y - 1;
        }
        return z;
    }
    public void solve() throws IOException {
        // write your code here
        int n = nextInt();
        int m = nextInt();
        int g = nextInt();
        mo = new int[n][m];   // movements
        boolean[][] rob = new boolean[n][m];     /// is there robot
        int[][] typ = new int[n][m];             /// types;
        int koltyp = 0;                        /// kolvo typov
        String S;
        char[] c;
        for (int i = 0; i < n; i++){
            S = nextToken();
            c = S.toCharArray();
            for (int j = 0; j < m; j++){
                if ((c[j] == 'N')||(c[j] == 'E')||(c[j] == 'W')||(c[j] == 'S')){
                    rob[i][j] = true;
                }
                if ((c[j] == 'N')||(c[j] == 'n')){
                    mo[i][j] = 0;
                }
                if ((c[j] == 'E')||(c[j] == 'e')){
                    mo[i][j] = 1;
                }
                if ((c[j] == 'S')||(c[j] == 's')){
                    mo[i][j] = 2;
                }
                if ((c[j] == 'W')||(c[j] == 'w')){
                    mo[i][j] = 3;
                }
            }
        }
        int[] oftyp = new int[n * m + 1]; // robotov dannogo typa
        int[] kloftyp = new int[n * m + 1];   // kletok dannogo typa
        int[] ltsikl = new int[n * m + 1];   // dlina tsikla dannogo typa;
        //finding types and numbers
        int[][] curr = new int[n * m][2];
        int lcurr;
        int ro; // robotov dannogo typa
        int[] t = new int[2];
        for (int i = 0; i < n; i++){
            for (int j = 0; j < m; j++){
                koltyp++;
                t[0] = i;
                t[1] = j;
                lcurr = 0;
                ro = 0;
                while (typ[t[0]][t[1]] == 0){
                    lcurr++;
                    curr[lcurr - 1][0] = t[0];
                    curr[lcurr - 1][1] = t[1];
                    if (rob[t[0]][t[1]]){
                        ro++;
                    }
                    typ[t[0]][t[1]] = koltyp;
                    t = func(t);
                }
                if (typ[t[0]][t[1]] < koltyp){
                    for (int l = 0; l < lcurr; l++){
                        typ[curr[l][0]][curr[l][1]] = typ[t[0]][t[1]];
                    }
                    oftyp[typ[t[0]][t[1]]] += ro;
                    kloftyp[typ[t[0]][t[1]]] += lcurr;
                    koltyp--;
                }
                else{
                    oftyp[koltyp] = ro;
                    kloftyp[koltyp] = lcurr;
                    int nu = 0;   // nomer t v massive curr
                    while ((curr[nu][0] != t[0])||(curr[nu][1] != t[1])){
                        nu++;
                    }
                    ltsikl[koltyp] = lcurr - nu;
                }
            }
        }
        int totrob = 0;   // total robots
        for (int i = 1; i <= koltyp; i++){
            totrob += Math.min(ltsikl[i], oftyp[i]);
        }
        out.println(totrob);
        //
        if (g == 1) {
            //beg po typam
            boolean[] used = new boolean[n * m + 1];   /// used this type?
            boolean[][] used2 = new boolean[n][m];     // bila li vershina v bfs
            int[][] q = new int[n * m + 1][2];         // ochered
            int lq;
            int rq;
            int[][] time = new int[n][m];           /// vremya BFS
            int[][] time2 = new int[n][m];         // vremya zapuska
            for (int i = 0; i < n; i++){
                for (int j = 0; j < m; j++){
                    if (!used[typ[i][j]]){
                        t[0] = i;
                        t[1] = j;
                        for (int s = 0; s < kloftyp[typ[i][j]] + 3; s++){
                            t = func(t);
                        }
                        // teper mi nashli vershinu tsikla
                        lq = 0;
                        rq = 0;
                        q[0][0] = t[0];
                        q[0][1] = t[1];
                        used2[t[0]][t[1]] = true;
                        time[t[0]][t[1]] = 1;
                        while (lq <= rq){
                            if (q[lq][0] > 0){
                                if (mo[q[lq][0] - 1][q[lq][1]] == 2){
                                    if (!used2[q[lq][0] - 1][q[lq][1]]){
                                        rq++;
                                        q[rq][0] = q[lq][0] - 1;
                                        q[rq][1] = q[lq][1];
                                        used2[q[rq][0]][q[rq][1]] = true;
                                        time[q[rq][0]][q[rq][1]] = time[q[lq][0]][q[lq][1]] + 1;
                                    }
                                }
                            }
                            if (q[lq][0] < n - 1){
                                if (mo[q[lq][0] + 1][q[lq][1]] == 0){
                                    if (!used2[q[lq][0] + 1][q[lq][1]]){
                                        rq++;
                                        q[rq][0] = q[lq][0] + 1;
                                        q[rq][1] = q[lq][1];
                                        used2[q[rq][0]][q[rq][1]] = true;
                                        time[q[rq][0]][q[rq][1]] = time[q[lq][0]][q[lq][1]] + 1;
                                    }
                                }
                            }
                            if (q[lq][1] > 0){
                                if (mo[q[lq][0]][q[lq][1] - 1] == 1){
                                    if (!used2[q[lq][0]][q[lq][1] - 1]){
                                        rq++;
                                        q[rq][0] = q[lq][0];
                                        q[rq][1] = q[lq][1] - 1;
                                        used2[q[rq][0]][q[rq][1]] = true;
                                        time[q[rq][0]][q[rq][1]] = time[q[lq][0]][q[lq][1]] + 1;
                                    }
                                }
                            }
                            if (q[lq][1] < m - 1){
                                if (mo[q[lq][0]][q[lq][1] + 1] == 3){
                                    if (!used2[q[lq][0]][q[lq][1] + 1]){
                                        rq++;
                                        q[rq][0] = q[lq][0];
                                        q[rq][1] = q[lq][1] + 1;
                                        used2[q[rq][0]][q[rq][1]] = true;
                                        time[q[rq][0]][q[rq][1]] = time[q[lq][0]][q[lq][1]] + 1;
                                    }
                                }
                            }
                            lq++;
                        }
                        boolean[] zan = new boolean[ltsikl[typ[i][j]] + 1];   // zanyatie ostatki
                        int minzan = 0;
                        int re = 0;
                        for (int s = 0; s <= rq; s++){
                            if (rob[q[s][0]][q[s][1]]) {
                                if (minzan < ltsikl[typ[i][j]]){
                                    time2[q[s][0]][q[s][1]] = minzan - time[q[s][0]][q[s][1]] + 1;
                                    time2[q[s][0]][q[s][1]] += ((time[q[rq][0]][q[rq][1]]/ltsikl[typ[i][j]]) + 1) * ltsikl[typ[i][j]];
                                    if (s > 0){
                                        if (time[q[s][0]][q[s][1]] == time[q[s-1][0]][q[s-1][1]]){
                                            re++;
                                        }
                                        else{
                                            re = 0;
                                        }
                                        time2[q[s][0]][q[s][1]] += re * ltsikl[typ[i][j]];
                                    }
                                    zan[minzan] = true;
                                    while (zan[minzan]){
                                        minzan++;
                                    }
                                }
                            }
                        }
                        // teper vremena rasstavleny
                        used[typ[i][j]] = true;
                    }
                }
            }
            for (int i = 0; i < n; i++){
                for (int j = 0; j < m; j++){
                    if (rob[i][j]){
                        if ((time2[i][j] > 0)){
                            out.print(i + 1);
                            out.print(" ");
                            out.print(j + 1);
                            out.print(" ");
                            out.println(time2[i][j]);
                        }
                    }
                }
            }
        }
        out.close();
    }

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

            solve();

            out.close();
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    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) throws IOException {
        Locale.setDefault(Locale.US);
        new B().run();
    }

}
