#include <bits/stdc++.h>
#define time jsadfksdaf
#define fi first
#define se second
using namespace std;

const int N = 1e3;

int n, m, g;
vector<string> a;
bool used[N][N], iscyc[N][N];
int col[N][N], dist[N][N], len[N * N], tocyc[N][N], time[N * N], placed[N * N], pos[N][N];
int C = 0;

void allclear() {
    memset(col, -1, sizeof col);
    memset(dist, 0, sizeof dist);
    memset(len, 0, sizeof len);
    memset(used, 0, sizeof used);
    memset(iscyc, 0, sizeof iscyc);
    memset(tocyc, -1, sizeof tocyc);
    memset(time, 0, sizeof time);
    memset(placed, 0, sizeof placed);
    memset(pos, -1, sizeof pos);
    C = 0;
}

int dx(char c) {
    if (tolower(c) == 'w') return -1;
    if (tolower(c) == 'e') return 1;
    return 0;
}

int dy(char c) {
    if (tolower(c) == 'n') return -1;
    if (tolower(c) == 's') return 1;
    return 0;
}

void findcycle(int i, int j, int d) {
    used[i][j] = true;
    dist[i][j] = d;

    int newi = i + dy(a[i][j]);
    int newj = j + dx(a[i][j]);
    if (used[newi][newj] == true) {
        if (col[newi][newj] != -1) {
            col[i][j] = col[newi][newj];
            pos[i][j] = pos[newi][newj];
        } else {
            len[C] = dist[i][j] - dist[newi][newj] + 1;
            col[i][j] = C++;

            int vi = newi, vj = newj, k = 0;
            while (vi != i || vj != j) {
                pos[vi][vj] = k++;
                iscyc[vi][vj] = true;
                int pi = vi, pj = vj;
                vi += dy(a[pi][pj]);
                vj += dx(a[pi][pj]);
            }
            pos[vi][vj] = k;
            iscyc[i][j] = true;
        }
    } else {
        findcycle(newi, newj, d + 1);
        col[i][j] = col[newi][newj];
        pos[i][j] = pos[newi][newj];
    }
}

void gocyc(int i, int j) {
    if (iscyc[i][j]) {
        tocyc[i][j] = 0;
        return;
    }
    int newi = i + dy(a[i][j]);
    int newj = j + dx(a[i][j]);
    if (tocyc[newi][newj] == -1) gocyc(newi, newj);
    tocyc[i][j] = tocyc[newi][newj] + 1;
}

void solve() {
    a.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (!used[i][j]) {
                findcycle(i, j, 0);
            }
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (tocyc[i][j] == -1) {
                gocyc(i, j);
            }
        }
    }
/*
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cout << tocyc[i][j];
        }
        cout << endl;
    }*/

    int ans = 0;
    vector< pair< pair<int, int>, int > > rev;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (toupper(a[i][j]) == a[i][j]) {
                if (placed[col[i][j]] < len[col[i][j]]) {
                    int curtime = time[col[i][j]];
                    int delay = len[col[i][j]] - pos[i][j];
                    curtime += delay;
                    curtime -= tocyc[i][j];
                    ans++;
                    placed[col[i][j]]++;
                    time[col[i][j]] += len[col[i][j]];
                    rev.push_back({{i, j}, curtime + 100});
                }
            }
        }
    }

    printf("%d\n", ans);
    if (g == 1) {
        for (auto p : rev) {
            printf("%d %d %d\n", p.fi.fi + 1, p.fi.se + 1, p.se);
        }
    }
}

int main() {
    freopen("robots.in", "r", stdin);
    freopen("robots.out", "w", stdout);

    while (scanf("%d%d%d", &n, &m, &g) == 3) {
        allclear();
        solve();
    }
}
