#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const int mn = 1025;
typedef pair <long long, long long> pll;
long long n, m, g, lci, lcj, ans;
pll p[mn][mn];
long long was[mn][mn], cnt[mn][mn], cnt2[mn][mn], steps[mn][mn], cnt3[mn][mn];
bool cyc[mn][mn];
char a[mn][mn];

pll found(pll q) {
	if (p[q.first][q.second] == q) {
		steps[q.first][q.second] = 0;
		return q;
	}
	pll w = found(p[q.first][q.second]);
	if (steps[q.first][q.second] == 0) {
		steps[q.first][q.second] = steps[p[q.first][q.second].first][p[q.first][q.second].second] + 1;
	}
	p[q.first][q.second] = w;
	return w;
}

void dfs(int i, int j) {
	if (was[i][j] == 2) {
		return;
	}
	if (was[i][j] == 1) {
		cyc[i][j] = true;
		lci = i;
		lcj = j;
		was[i][j] = 2;
		return;
	}
	was[i][j] = 1;
	if (a[i][j] == 'N' || a[i][j] == 'n') {
		dfs(i - 1, j);
		p[i][j] = make_pair(i - 1, j);
		if (lci != -1) {
			cyc[i][j] = true;
		}
		if (lci == i && lcj == j) {
			p[i][j] = make_pair(lci, lcj);
			lci = -1;
		}
	}
	if (a[i][j] == 'W' || a[i][j] == 'w') {
		dfs(i, j - 1);
		p[i][j] = make_pair(i, j - 1);
		if (lci != -1) {
			cyc[i][j] = true;
		}
		if (lci == i && lcj == j) {
			p[i][j] = make_pair(lci, lcj);
			lci = -1;
		}
	}
	if (a[i][j] == 'E' || a[i][j] == 'e') {
		dfs(i, j + 1);
		p[i][j] = make_pair(i, j + 1);
		if (lci != -1) {
			cyc[i][j] = true;
		}
		if (lci == i && lcj == j) {
			p[i][j] = make_pair(lci, lcj);
			lci = -1;
		}
	}
	if (a[i][j] == 'S' || a[i][j] == 's') {
		dfs(i + 1, j);
		p[i][j] = make_pair(i + 1, j);
		if (lci != -1) {
			cyc[i][j] = true;
		}
		if (lci == i && lcj == j) {
			p[i][j] = make_pair(lci, lcj);
			lci = -1;
		}
	}
	was[i][j] = 2;
}

void dfs2(int i, int j) {
	if (was[i][j] == 1) {
		return;
	}
	was[i][j] = 1;
	pll w = make_pair(i, j);
	w = found(w);
	cnt2[w.first][w.second]++;
	if (a[i][j] == 'N' || a[i][j] == 'n') {
		dfs2(i - 1, j);
	}
	if (a[i][j] == 'W' || a[i][j] == 'w') {
		dfs2(i, j - 1);
	}
	if (a[i][j] == 'E' || a[i][j] == 'e') {
		dfs2(i, j + 1);
	}
	if (a[i][j] == 'S' || a[i][j] == 's') {
		dfs2(i + 1, j);
	}
}

int main() {
	freopen("robots.in", "r", stdin);
	freopen("robots.out", "w", stdout);
	cin >> n >> m >> g;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> a[i][j];
			was[i][j] = 0;
			cyc[i][j] = false;
			cnt[i][j] = 0;
			steps[i][j] = 0;
			p[i][j] = make_pair(i, j);
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			lci = -1;
			lcj = -1;
			if (was[i][j] == 0) {
				dfs(i, j);
			}
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			was[i][j] = 0;
			if (a[i][j] == 'N' || a[i][j] == 'S' || a[i][j] == 'W' || a[i][j] == 'E') {
				pll w = make_pair(i, j);
				w = found(w);
				cnt[w.first][w.second]++;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (was[i][j] == 0 && cyc[i][j]) {
				dfs2(i, j);
			}
		}
	}
	ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			ans += min(cnt[i][j], cnt2[i][j]);
			cnt3[i][j] = 0;
		}
	}
	cout << ans << "\n";
	if (g == 1) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (a[i][j] == 'N' || a[i][j] == 'S' || a[i][j] == 'W' || a[i][j] == 'E') {
					pll w = make_pair(i, j);
					w = found(w);
					if (cnt2[w.first][w.second] > cnt3[w.first][w.second]) {
						cout << i + 1 << " " << j + 1 << " " << cnt2[w.first][w.second] + cnt3[w.first][w.second] - (steps[i][j] % cnt2[w.first][w.second]) << "\n";
						cnt3[w.first][w.second]++;
					}
				}
			}
		}
	}
	return 0;
}