#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define size(x) (int) x.size()
#define all(x) x.begin(), x.end()

const int maxn = 1005;
const int inf = (int) 1e9;
const long long mod = (long long) 1e9 + 7;
const long long l_inf = (long long) 4e18;

struct Result {
    int r, c, t;
};

int n, m, type;
bool isRobot[maxn * maxn];
int g[maxn * maxn];

int used[maxn * maxn];
bool cycle[maxn * maxn];
int top[maxn * maxn], sz[maxn * maxn], dist[maxn * maxn], dep[maxn * maxn];
int last[maxn * maxn], cnt[maxn * maxn];
vector<Result> res;

void dfs1(int v) {
    used[v] = 1;
    if (used[g[v]] != 0) {
        if (top[g[v]] == -1) {
            sz[v] = dep[v] - dep[g[v]] + 1;
            top[v] = v;
            dist[v] = 0;
        } else {
            top[v] = top[g[v]];
            dist[v] = dist[g[v]] + 1;
        }
    } else {
        dep[g[v]] = dep[v] + 1;
        dfs1(g[v]);
        top[v] = top[g[v]];
        dist[v] = dist[g[v]] + 1;
    }
}

void dfs2(int v) {
    if (isRobot[v] && cnt[top[v]] < sz[top[v]]) {
        int t = (last[top[v]] + 1 - dist[v]) % sz[top[v]];
        if (t <= 0)
            t += sz[top[v]];
        res.pb({v / m + 1, v % m + 1, t});
        last[top[v]] = t + dist[v];
        cnt[top[v]]++;
    }

    used[v] = 2;
    if (used[g[v]] != 2)
        dfs2(g[v]);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	cout << fixed;
	srand(566);

#ifndef LOCAL
#define FILE "robots"
	freopen(FILE".in", "r", stdin);
	freopen(FILE".out", "w", stdout);
#endif

    scanf("%d %d %d ", &n, &m, &type);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            char side;
            scanf("%c ", &side);
            if (side == toupper(side))
                isRobot[i * m + j] = true;
            side = toupper(side);
            if (side == 'S') {
                g[i * m + j] = ((i + 1) * m + j);
            }
            if (side == 'N') {
                g[i * m + j] = ((i - 1) * m + j);
            }
            if (side == 'E') {
                g[i * m + j] = (i * m + (j + 1));
            }
            if (side == 'W') {
                g[i * m + j] = (i * m + (j - 1));
            }
        }
    }

    memset(top, -1, sizeof top);
    for (int i = 0; i < n * m; i++) {
        if (used[i] == 0) {
            dfs1(i);
            dfs2(i);
        }
    }

    printf("%d\n", size(res));
    if (type == 1)
        for (Result x : res)
            printf("%d %d %d\n", x.r, x.c, x.t);



	return 0;
}


