// B_WRO.cpp : Defines the entry point for the console application.
//

#include <fstream>
#include <vector>
#include <stack>

using namespace std;

ifstream fin("robots.in");
ofstream fout("robots.out");

int n, m, g;
long long ans = 0;
vector <int> path, cur, tocyc;
vector <bool> vis, used, look;
vector <pair <int, int> > cyc;
vector <vector <int> > fre;
vector <vector <bool> > isfil;
vector <int> tick, fil;

/*int dfs(int v, int move, int fir)
{
	vis[v] = true;

	if (path[v] == fir)
		return move + 1;
	if (vis[path[v]])
		return -1;
	return dfs(path[v], move + 1, fir);
}*/

pair <int, int> dfs(int v)
{
	if (tocyc[v] != -1)
		return make_pair(0, tocyc[v]);
	auto p = dfs(path[v]);
	if (cur[v] == 1)
		p.first++;
	tocyc[v] = p.second;
	return p;
}

int main()
{
	fin >> n >> m >> g;

	path.clear();
	path.resize(n * m, 0);
	cur = path;
	cyc.clear();
	used.clear();
	used.resize(n * m, false);
	fre.clear();
	tocyc.clear();
	tocyc.resize(n * m, -1);

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			char c;
			fin >> c;
			int ind = i * m + j;
			if (c == 'S' || c == 's')
				path[ind] = ind + m;
			if (c == 'N' || c == 'n')
				path[ind] = ind - m;
			if (c == 'W' || c == 'w')
				path[ind] = ind - 1;
			if (c == 'E' || c == 'e')
				path[ind] = ind + 1;
			if (c == 'N' || c == 'S' || c == 'W' || c == 'E')
				cur[ind] = 1;
		}
	}

	isfil.clear();

	for (int i = 0; i < n * m; i++)
	{
		if (used[i])
			continue;
		vis.clear();
		vis.resize(n * m, false);
		//int res = dfs(i, 0, i);
		int p = path[i];
		vis[i] = true;
		int res = 1;
		while (p != i)
		{
			vis[p] = true;
			if (vis[path[p]] && path[p] != i)
				break;
			res++;
			p = path[p];
		}
		if (p != i)
			res = -1;
		if (res != -1)
		{
			cyc.push_back(make_pair(i, res));
			vector <int> fred;
			vector <bool> no;
			no.clear();
			fred.clear();
			used[i] = true;
			if (cur[i] == 0)
				fred.push_back(i);
			tocyc[i] = cyc.size() - 1;
			int p = path[i];
			while (p != i)
			{
				used[p] = true;
				tocyc[p] = cyc.size() - 1;
				if (cur[p] == 0)
					fred.push_back(p);
				p = path[p];
			}
			no.resize(fred.size(), false);
			isfil.push_back(no);
			fre.push_back(fred);
		}
	}

	look.clear();
	look.resize(n * m, false);

	if (g == 0)
	{
		for (int i = 0; i < n * m; i++)
		{
			if (used[i])
				continue;
			int p = i;
			auto pp = dfs(p);
			int cnt = pp.first;

			/*while (tocyc[p] == -1)
			{
				if (cur[p] == 1 && !look[p])
					cnt++;
				look[p] = true;
				p = path[p];
			}
			/*if (cur[p] == 1 && !look[p])
				cnt++;
			look[p] = true;*/
			if (cnt >= fre[pp.second].size())
				fre[pp.second].clear();
			else
				fre[pp.second].resize(fre[pp.second].size() - cnt);
		}

		for (int i = 0; i < cyc.size(); i++)
			ans += cyc[i].second - fre[i].size();

		fout << ans;

	}
	else
	{
		tick.clear();
		tick.resize(n * m, -1);
		fil.clear();
		fil.resize(cyc.size(), 0);
		stack <int> tofil, mto;
		while (!tofil.empty())
			tofil.pop();
		while (!mto.empty())
			mto.pop();

		for (int i = 0; i < n * m; i++)
		{
			if (used[i] || cur[i] == 0 || look[i])
				continue;
			int p = i;
			int cnt = 0;
			int move = 0;
			look[i] = true;

			while (tocyc[p] == -1)
			{
				if (cur[p] == 1 && !look[p])
				{
					cnt++;
					tofil.push(p);
					mto.push(move);
				}
				look[p] = true;
				p = path[p];
				move++;
			}
			while (fre[tocyc[p]].size() > fil[tocyc[p]] && !tofil.empty())
			{
				int nx = tofil.top();
				tofil.pop();
				int m0 = move - mto.top();
				mto.pop();
				int k = 0;
				for (; k < fre[tocyc[p]].size() && isfil[tocyc[p]][k]; k++);
				if (k == fre[tocyc[p]].size())
					break;
				int em = fre[tocyc[p]][k];
				isfil[tocyc[p]][k] = true;
				//fil[tocyc[p]]++;
				int mem = 0;
				while (em != p)
				{
					em = path[em];
					mem++;
				}
				tick[nx] = em - m0;
				while (tick[nx] < 0)
					tick[nx] += cyc[tocyc[p]].second;
				tick[nx]++;
				fil[tocyc[p]]++;
			}
			/*if (cnt > fre[tocyc[p]].size())
				continue;
			else
			{
				cnt--;
				int em = fre[tocyc[p]][cnt];
				int mem = 0;
				while (em != p)
				{
					em = path[em];
					mem++;
				}
				tick[i] = em - move;
				while (tick[i] < 0)
					tick[i] += cyc[tocyc[p]].second;
				tick[i]++;
				fil[tocyc[p]]++;
			}*/
			/*if (cur[p] == 1 && !look[p])
			cnt++;
			look[p] = true;*/
			/*if (cnt >= fre[tocyc[p]].size())
				fre[tocyc[p]].clear();
			else
				fre[tocyc[p]].resize(fre[tocyc[p]].size() - cnt);*/
		}

		for (int i = 0; i < cyc.size(); i++)
			ans += cyc[i].second - fre[i].size() + fil[i];

		fout << ans << '\n';
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < m; j++)
			{
				int ind = i * m + j;
				if (cur[ind] == 0)
					continue;
				if (tocyc[ind] != -1)
					fout << i + 1 << ' ' << j + 1 << ' ' << 1 << '\n';
				else if (tick[ind] != -1)
					fout << i + 1 << ' ' << j + 1 << ' ' << tick[ind] << '\n';
			}
		}
	}

	
		
	return 0;
}