#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <string>

using namespace std;

struct p {
    int x;
    int y;
};

int cur = 1;
char a[1000][1000];
int been[1000][1000];
int far[1000][1000];
pair <int, int> nex[1000][1000];
//vector <vector <p> > cicles;
vector <p> path;
int maxx[1000000];
int curr[1000000];
int curr2[1000000];

void dfs(p v) {
    p u;
    u.x = v.x;
    u.y = v.y;
    path.push_back(v);
    been[v.x][v.y] = cur;
    if (a[v.x][v.y] == 's' || a[v.x][v.y] == 'S') {
        u.x += 1;
        //cout << "Var1" << endl;
    }
    else if (a[v.x][v.y] == 'n' || a[v.x][v.y] == 'N') {
        u.x -= 1;
        //cout << "Var2" << endl;
    }
    else if (a[v.x][v.y] == 'e' || a[v.x][v.y] == 'E') {
        u.y += 1;
        //cout << "Var3" << endl;
    }
    else if (a[v.x][v.y] == 'w' || a[v.x][v.y] == 'W') {
        u.y -= 1;
        //cout << "Var4" << endl;
    }
    //cout << v.x << " " << v.y << ", " << u.x << " " << u.y << "; " << cur << endl;
    if (been[u.x][u.y] == 0) {
        //been[u.x][u.y] = cur;
        dfs(u);
    }
    else {
        if (been[u.x][u.y] == cur) {
            int i = path.size() - 1;
            int o = 0;
            while (path[i].x != u.x || path[i].y != u.y) {
                nex[path[i].x][path[i].y] = make_pair(cur, 0);
                far[path[i].x][path[i].y] = o;
                i -= 1;
                o += 1;
            }
            nex[path[i].x][path[i].y] = make_pair(cur, 0);
            far[path[i].x][path[i].y] = o;
            o += 1;
            i -= 1;
            int c = 1;
            while (i >= 0) {
                nex[path[i].x][path[i].y] = make_pair(cur, c);
                far[path[i].x][path[i].y] = o;
                i -= 1;
                c += 1;
                o += 1;
            }
            path.clear();
        }
        else {
            int i = path.size() - 1;
            int c = nex[u.x][u.y].second + 1;
            int o = far[u.x][u.y] + 1;
            int cur2 = nex[u.x][u.y].first;
            while (i >= 0) {
                nex[path[i].x][path[i].y] = make_pair(cur2, c);
                far[path[i].x][path[i].y] = o;
                i -= 1;
                c += 1;
                o += 1;
            }
            path.clear();
        }
    }
}

int main() {
    freopen("robots.in", "r", stdin);
    freopen("robots.out", "w", stdout);
    int n, m, g;
    char x;
    cin >> n >> m >> g;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (been[i][j] == 0) {
                p q;
                q.x = i;
                q.y = j;
                dfs(q);
                cur += 1;
            }
        }
    }
    //for (int i = 0; i < n; i++) {
        //for (int j = 0; j < m; j++) {
            //cout << far[i][j] << ", ";
        //}
        //cout << endl;
    //}
    int summ = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (nex[i][j].second == 0) {
                maxx[nex[i][j].first] += 1;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if ((a[i][j] == 'S' || a[i][j] == 'N' || a[i][j] == 'W' || a[i][j] == 'E') && curr[nex[i][j].first] < maxx[nex[i][j].first]) {
                curr[nex[i][j].first] += 1;
                //cout << i + 1 << " " << j + 1 << " " << (1000000 + curr[nex[i][j].first] - far[i][j]) % maxx[nex[i][j].first] << endl;
                summ += 1;
            }
        }
    }
    cout << summ << endl;
    if (g == 1) {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if ((a[i][j] == 'S' || a[i][j] == 'N' || a[i][j] == 'W' || a[i][j] == 'E') && curr2[nex[i][j].first] < maxx[nex[i][j].first]) {
                curr2[nex[i][j].first] += 1;
                cout << i + 1 << " " << j + 1 << " " << (1000000 + curr2[nex[i][j].first] - far[i][j]) % maxx[nex[i][j].first] << endl;
                summ += 1;
            }
        }
    }
    }
    fclose(stdin);
    fclose(stdout);
}
