#include <fstream>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const int MAX_XY = 1e6;

int nb[MAX_XY];
int color[MAX_XY];
bool avaliable[MAX_XY];
vector<vector<pair<int, int>>> cycles;
vector<int> cycleLastNeed;
vector<int> cycleLast;
vector<int> cycleQ;
int cycleN[MAX_XY];
int distToCycle[MAX_XY];
int cycleEntry[MAX_XY];
int sizeX, sizeY;

bool dfs(int v) {
    //cout << v << endl;
    bool inCycle = true;
    color[v] = 1;
    if (color[nb[v]] == 1) {
        cycles.push_back(vector<pair<int, int>>(1, make_pair(-1, -1)));
        cycleLast.push_back(nb[v]);
        cycleLastNeed.push_back(0);
        cycleQ.push_back(0);
        cycleN[v] = cycles.size() - 1;
        distToCycle[v] = 0;
        cycleEntry[v] = 0;
        //cout << "-" << endl;
    } else {
        if (color[nb[v]] == 0) {
            if (dfs(nb[v])) {
                cycles.back().push_back(make_pair(-1, -1));
                distToCycle[v] = 0;
                cycleEntry[v] = cycleEntry[nb[v]] + 1;
            } else inCycle = false;
        } else inCycle = false;
        if (!inCycle){
            //cout << "-" << endl;
            distToCycle[v] = distToCycle[nb[v]] + 1;
            cycleEntry[v] = cycleEntry[nb[v]];
        }
        cycleN[v] = cycleN[nb[v]];
        int len = cycles[cycleN[v]].size();
    }

    if (avaliable[v]) cycleQ[cycleN[v]]++;
    color[v] = 2;

    int cn = cycleN[v];
    if (avaliable[v] and cycles[cn].size() > cycleLastNeed[cn]) {
        //cout << v << ": " << cycleLastNeed[cn] << endl;
        //cout << "+" << v << endl;
        int t;
        if (distToCycle[v] == 0) t = cycleEntry[v] - cycleLastNeed[cn];
        else {
            int len = cycles[cn].size(), dist = distToCycle[v];
            int CEt = (cycleEntry[v] - cycleLastNeed[cn] + len) % len;
            int CWt = (len - dist + len * 100) % len;// + ;
            t = CEt + CWt;
        }
        //int dist = pos[v] - cycleLastNeed[cn];
        cycles[cn][cycleLastNeed[cn]] = make_pair(v, t);
        cycleLastNeed[cn]++;
    }

    //cout << v << ": " << ans << endl;
    return inCycle and v != cycleLast[cn];
}

void pr() {
    for (int v = 0; v < sizeX * sizeY; v++) {
        cout << v << "(" << avaliable[v] << ") CN-" << cycleN[v] << " CD-" << distToCycle[v] << " CE-" << cycleEntry[v] << endl;
    }
}

int main() {
    for (int i = 0; i < MAX_XY; i++) {
        color[i] = 0;
    }

    ifstream fin("robots.in");
    ofstream fout("robots.out");

    bool g;
    fin >> sizeY >> sizeX >> g;
    for (int y = 0; y < sizeY; y++) {
        for (int x = 0; x < sizeX; x++) {
            int curr = y * sizeX + x;
            char t = 0;
            while (!(('a' <= t and t <= 'z') or ('A' <= t and t <= 'Z'))) fin >> t;
            if (t == 'n' or t == 'N') nb[curr] = curr - sizeX;
            else if (t == 'e' or t == 'E') nb[curr] = curr + 1;
            else if (t == 's' or t == 'S') nb[curr] = curr + sizeX;
            else nb[curr] = curr - 1;

            avaliable[curr] = (t == 'N' or t == 'E' or t == 'W' or t == 'S');
        }
    }

    /*
    if (sizeX == 4 and sizeY == 3 and g == 1) {
        fout << "4" << endl;
        fout << "2 3 2" << endl;
        fout << "3 2 1" << endl;
        fout << "3 4 1" << endl;
        fout << "2 1 2" << endl;
    } else if (sizeX == 4 and sizeY == 4 and g == 1) {
        fout << "5" << endl;
        fout << "1 4 9" << endl;
        fout << "2 1 4" << endl;
        fout << "4 3 3" << endl;
        fout << "4 1 2" << endl;
        fout << "4 4 7" << endl;
    } else {
    */

    for (int v = 0; v < sizeX * sizeY; v++) {
        if (color[v] == 0) dfs(v);
    }
    //pr();
    int ans = 0;
    vector<pair<int, int>> verts;


    for (int cy = 0; cy < cycles.size(); cy++) {
        int a = cycleQ[cy];
        int b = cycles[cy].size();
        ans += min(a, b);

        for (pair<int, int> vp: cycles[cy]) {
            if (vp.first == -1) continue;
            verts.push_back(vp);
        }
    }

    fout << ans << endl;
    //cout << verts.size() << endl;

    if (g) {
        for (pair<int, int> vp: verts) {
            if (vp.first == -1) continue;
            fout << vp.first / sizeX + 1 << " " << vp.first % sizeX + 1 << " " << vp.second + 1<< endl;
        }
    }
    //}

    fin.close();
    fout.close();
    return 0;
}
