#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#pragma comment(linker, "/stack:268435456")
#define cs(x) (int)x.size()
#define ll long long
#define ld long double
#define mp make_pair

using namespace std;

const int MAXN = 1000;

int dx[4] = { -1, 0, 1, 0 };
int dy[4] = { 0, 1, 0, -1 };

int field[MAXN][MAXN];
int belongtocicl[MAXN][MAXN];
int dist[MAXN][MAXN];
bool isrobot[MAXN][MAXN];
pair<int, int> ciclstatus[MAXN][MAXN];
vector<int> cicles;
vector<int> used;
int n, m, g;

/*
-3 = Precicl, second = length to...
> 0 = Cicl num, second undefined

*/

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

vector<pair<int, int> > curcicl;

pair<int, int> dfs(int x, int y) {
	ciclstatus[x][y].first = -2;
	int to = field[x][y];
	int nx = x + dx[to];
	int ny = y + dy[to];
	if (ciclstatus[nx][ny].first >= 0) {
		ciclstatus[x][y] = mp(-3, ciclstatus[nx][ny].second - 1);
		dist[x][y] = dist[nx][ny] + 1;
		belongtocicl[x][y] = belongtocicl[nx][ny];
		if (ciclstatus[x][y].second < 0)
			ciclstatus[x][y].second += cicles[belongtocicl[x][y]];
		return mp(-1, -1);
	}
	if (ciclstatus[nx][ny].first == -3) {
		ciclstatus[x][y] = mp(-3, ciclstatus[nx][ny].second - 1);
		dist[x][y] = dist[nx][ny] + 1;
		belongtocicl[x][y] = belongtocicl[nx][ny];
		if (ciclstatus[x][y].second < 0)
			ciclstatus[x][y].second += cicles[belongtocicl[x][y]];
		return mp(-1, -1);
	}
	if (ciclstatus[nx][ny].first == -2) {
		curcicl.push_back(mp(x, y));
		return mp(nx, ny);
	}
	if (ciclstatus[nx][ny].first == -1) {
		auto result = dfs(nx, ny);
		belongtocicl[x][y] = belongtocicl[nx][ny];
		if (result.first == -1) {
			ciclstatus[x][y] = mp(-3, ciclstatus[nx][ny].second - 1);
			dist[x][y] = dist[nx][ny] + 1;
			if (ciclstatus[x][y].second < 0)
				ciclstatus[x][y].second += cicles[belongtocicl[x][y]];
			return result;
		}
		else {
			curcicl.push_back(mp(x, y));
			if (mp(x, y) != result)
				return result;
			else {
				ciclstatus[x][y] = mp(cs(cicles), 0);
				int q = 0;
				for (int j = cs(curcicl) - 1; j >= 0; j--) {
					auto v = curcicl[j];
					belongtocicl[v.first][v.second] = cs(cicles);
					ciclstatus[v.first][v.second] = mp(cs(cicles), q++);
					dist[v.first][v.second] = q;
				}
				cicles.push_back(cs(curcicl));
				curcicl.clear();
				return mp(-1, -1);
			}
		}
	}
}

ll toadd(ll a, ll mod) {
	return mod - (a % mod);
}

ll bigger(ll start, ll need, ll toadd) {
	if (start >= need)
		return start;
	ll delta = need - start;
	ll use = delta / toadd + (delta%toadd != 0);
	return start + use*toadd;
}

int main() {
	iostream::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	freopen("robots.in", "r", stdin);
	freopen("robots.out", "w", stdout);
	cin >> n >> m >> g;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		for (int j = 0; j < m; j++) {
			isrobot[i][j] = s[j] >= 'A' && s[j] <= 'Z';
			if (isrobot[i][j])
				s[j] = s[j] - 'A' + 'a';
			if (s[j] == 'n')
				field[i][j] = 0;
			if (s[j] == 'e')
				field[i][j] = 1;
			if (s[j] == 's')
				field[i][j] = 2;
			if (s[j] == 'w')
				field[i][j] = 3;
			ciclstatus[i][j] = mp(-1, -1);
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (ciclstatus[i][j].first == -1) {
				dfs(i, j);
			}
		}
	}
	used.resize(cs(cicles));
	vector<pair<pair<int, int>, ll> > ans;
	ll lasttime = 1;
	vector<vector<pair<int, pair<int, int> > > > need(cs(cicles));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (isrobot[i][j]) {
				if(ciclstatus[i][j].first == -3)
					need[belongtocicl[i][j]].push_back(mp(dist[i][j], mp(i, j)));
				else
					need[belongtocicl[i][j]].push_back(mp(-1, mp(i, j)));
			}
		}
	}
	for (auto arr : need) {
		if (cs(arr) == 0)
			continue;
		sort(arr.begin(), arr.end());
		int sz = cicles[belongtocicl[arr[0].second.first][arr[0].second.second]];
		int cur = 0;
		ll lasttime = 1;
		for (int i = 0; i < cs(arr); i++) {
			if (cur == sz)
				break;
			if (arr[i].first == -1) {
				auto v = arr[i].second;
				ll willbe = ciclstatus[v.first][v.second].second;
				willbe = bigger(willbe, lasttime, sz);
				willbe += cur;
				cur++;
				ans.push_back(mp(v, willbe));
			}
			else {
				int j = i;
				while (j + 1 < cs(arr) && arr[j + 1].first == arr[i].first)
					j++;
				ll tosetlasttime = lasttime;
				for (int z = i; z <= j; z++) {
					if (cur == sz)
						break;
					auto v = arr[z].second;
					ll willbe = ciclstatus[v.first][v.second].second;
					willbe += cur;
					willbe = bigger(willbe, lasttime, sz);
					cur++;
					ans.push_back(mp(v, willbe));
					tosetlasttime = max(tosetlasttime, willbe + 1);
				}
				lasttime = tosetlasttime;
				i = j;
			}
		}
	}
	cout << cs(ans) << "\n";
	if (g == 1) {
		for (auto el : ans)
			cout << el.first.first + 1 << " " << el.first.second + 1 << " " << el.second << "\n";
	}
	return 0;
}