#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define forq(i, q, n) for (int i = int(q); i < int(n); ++i)
#define mk make_pair
#define psh push_back
#define all(v) v.begin(), v.end()
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define Y second
#define X first
#define y1 asd
#define TASK "robots"

typedef long long ll;
typedef vector <int> vi;
typedef pair <int, int> pii;

const int MAXN = (int)1e3 + 7;
const int INF = (int)1e9 + 7;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;

void file()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#else
	freopen(TASK".in", "r", stdin); freopen(TASK".out", "w", stdout);
#endif
}

struct ee {
	int x, y, r;
};

char A[MAXN][MAXN];
int ans;
int used[MAXN][MAXN];
bool used1[MAXN][MAXN];
int n, m, g;
pii pr[MAXN][MAXN];
vector <ee> ans1;

bool ss(int x, int y) {
	return x >= 0 && y >= 0 && x < n && y < m;
}

vector <ee> chc;

void dfs1(int x, int y, int r) {
	used1[x][y] = 1;
	if (ss(x - 1, y)) {
		if ((A[x - 1][y] == 's' || A[x - 1][y] == 'S') && used1[x - 1][y] == 0) {
			dfs1(x - 1, y, r + 1);
		}
	}
	if (ss(x + 1, y)) {
		if ((A[x + 1][y] == 'n' || A[x + 1][y] == 'N') && used1[x + 1][y] == 0) {
			dfs1(x + 1, y, r + 1);
		}
	}
	if (ss(x, y - 1)) {
		if ((A[x][y - 1] == 'e' || A[x][y - 1] == 'E') && used1[x][y - 1] == 0 && ss(x, y - 1)) {
			dfs1(x, y - 1, r + 1);
		}
	}
	if (ss(x, y + 1)) {
		if ((A[x][y + 1] == 'w' || A[x][y + 1] == 'W') && used1[x][y + 1] == 0 && ss(x, y + 1)) {
			dfs1(x, y + 1, r + 1);
		}
	}
	if (A[x][y] > 'A' && A[x][y] < 'Z') {
		chc.psh({ x, y, r });
	}
}

int dfs2(int x, int y) {
	int ch = 0;
	used1[x][y] = 1;
	if (ss(x - 1, y)) {
		if ((A[x - 1][y] == 's' || A[x - 1][y] == 'S') && used1[x - 1][y] == 0) {
			ch += dfs2(x - 1, y);
		}
	}
	if (ss(x + 1, y)) {
		if ((A[x + 1][y] == 'n' || A[x + 1][y] == 'N') && used1[x + 1][y] == 0) {
			ch += dfs2(x + 1, y);
		}
	}
	if (ss(x, y - 1)) {
		if ((A[x][y - 1] == 'e' || A[x][y - 1] == 'E') && used1[x][y - 1] == 0 && ss(x, y - 1)) {
			ch += dfs2(x, y - 1);
		}
	}
	if (ss(x, y + 1)) {
		if ((A[x][y + 1] == 'w' || A[x][y + 1] == 'W') && used1[x][y + 1] == 0 && ss(x, y + 1)) {
			ch += dfs2(x, y + 1);
		}
	}
	if (A[x][y] > 'A' && A[x][y] < 'Z') {
		return ch + 1;
	}
	else {
		return ch;
	}
}

int kol;

bool comp(ee a, ee b) {
	return a.r % kol > b.r % kol;
}

void obr(int x, int y, int x1, int y1) {
	kol = 1;
	while (x != x1 || y != y1) {
		pii p = pr[x][y];
		x = p.X;
		y = p.Y;
		kol++;
	}
	memset(used1, 0, sizeof(MAXN * MAXN));
	if (g == 1) {
		chc = vector <ee>(0);
		dfs1(x, y, 0);
		ans += min(kol, (int)chc.size());
		if (chc.size() != 0) {
			sort(all(chc), comp);
			int M = chc[0].r % kol;
			ans1.psh({ chc[0].x, chc[0].y, 1 });
			forq(i, 1, min(kol, (int)chc.size())) {
				M--;
				if (M < 0) {
					M += kol;
				}
				ans1.psh({ chc[i].x, chc[i].y, 1 + (M - (chc[i].r % kol) + kol) % kol });
			}
		}
	}
	else {
		int ch = dfs2(x, y);
		ans += min(kol, ch);
	}
}

void dfs(int x, int y) {
	used[x][y] = 1;
	if (A[x][y] == 'w' || A[x][y] == 'W') {
		if (used[x][y - 1] == 1) {
			obr(x, y, x, y - 1);
		}
		else {
			if (used[x][y - 1] == 0) {
				pr[x][y - 1] = mk(x, y);
				dfs(x, y - 1);
			}
		}
	}
	if (A[x][y] == 'e' || A[x][y] == 'E') {
		if (used[x][y + 1] == 1) {
			obr(x, y, x, y + 1);
		}
		else {
			if (used[x][y + 1] == 0) {
				pr[x][y + 1] = mk(x, y);
				dfs(x, y + 1);
			}
		}
	}
	if (A[x][y] == 'n' || A[x][y] == 'N') {
		if (used[x - 1][y] == 1) {
			obr(x, y, x - 1, y);
		}
		else {
			if (used[x - 1][y] == 0) {
				pr[x - 1][y] = mk(x, y);
				dfs(x - 1, y);
			}
		}
	}
	if (A[x][y] == 's' || A[x][y] == 'S') {
		if (used[x + 1][y] == 1) {
			obr(x, y, x + 1, y);
		}
		else {
			if (used[x + 1][y] == 0) {
				pr[x + 1][y] = mk(x, y);
				dfs(x + 1, y);
			}
		}
	}
	used[x][y] = 2;
}

int main() {
	file();
	scanf("%d%d%d", &n, &m, &g);
	forn(i, n) {
		forn(j, m) {
			scanf(" %c", &A[i][j]);
		}
	}
	ans = 0;
	forn(i, n) {
		forn(j, m) {
			if (!used[i][j]) {
				dfs(i, j);
			}
		}
	}
	printf("%d\n", ans);
	if (g) {
		forn(i, ans) {
			printf("%d %d %d\n", ans1[i].x + 1, ans1[i].y + 1, ans1[i].r);
		}
	}
	return 0;
}