#include <bits/stdc++.h>

using namespace std;

const int MX_SZ = 1042;
const int BG = 1e+8;
char a[MX_SZ][MX_SZ];
int n, m;
int color[MX_SZ][MX_SZ];
bool rob[MX_SZ][MX_SZ], cycle[MX_SZ][MX_SZ];
int dist[MX_SZ][MX_SZ];
pair<int, int> v0;
bool rch;
vector<pair<int, int>> was;

inline pair<int, int> get_w(char c)
{
    if (c == 'w' or c == 'W')
    {
        return {0, -1};
    }
    if (c == 'e' or c == 'E')
    {
        return {0, 1};
    }
    if (c == 'n' or c == 'N')
    {
        return {-1, 0};
    }
    if (c == 's' or c == 'S')
    {
        return {1, 0};
    }
}

int dsu_sz[MX_SZ][MX_SZ], dsu_tm[MX_SZ][MX_SZ];
pair<int, int> dsu_p[MX_SZ][MX_SZ];
int crcl = 1;

pair<int, int> dsu_get(pair<int, int> cr)
{
    if (dsu_p[cr.first][cr.second].first == cr.first and dsu_p[cr.first][cr.second].second == cr.second)
    {
        return cr;
    }
    dsu_p[cr.first][cr.second] = dsu_get(dsu_p[cr.first][cr.second]);
    return dsu_p[cr.first][cr.second];
}

void dsu_unite(pair<int, int> x, pair<int, int> y, bool add)
{
    x = dsu_get(x);
    y = dsu_get(y);
    if (x.first != y.first or x.second != y.second)
    {
        if (dsu_sz[x.first][x.second] < dsu_sz[y.first][y.second])
        {
            swap(x, y);
        }
        dsu_p[y.first][y.second] = x;
        if (add)
        {
            dsu_sz[x.first][x.second] += dsu_sz[y.first][y.second];
        }
    }
}

void dfs_cycle(int x, int y, int dst)
{
    if (dst == 0 or x != v0.first or y != v0.second)
    {
        dist[x][y] = dst;
        cycle[x][y] = true;
        dsu_unite({x, y}, v0, true);
        pair<int, int> mod = get_w(a[x][y]);
        dfs_cycle(x + mod.first, y + mod.second, dst + 1);
    }
}

void dfs(int x, int y)
{
    color[x][y] = crcl;
    was.push_back({x, y});
    pair<int, int> mod = get_w(a[x][y]);
    int nx = x + mod.first, ny = y + mod.second;
    if (color[nx][ny] == crcl and !cycle[nx][ny])
    {
        v0 = {nx, ny};
        dfs_cycle(nx, ny, 0);
    }
    if (color[nx][ny] != 0)
    {
        int cdist = dist[nx][ny];
        for (int j = (int)was.size() - 1; j >= 0; j--)
        {
            pair<int, int> prv = was[j];
            if (!cycle[prv.first][prv.second])
            {
                cdist++;
                if (dist[prv.first][prv.second] == -1)
                {
                    dist[prv.first][prv.second] = cdist;
                }
            }
            dsu_unite(prv, {nx, ny}, false);
        }
        return;
    }
    else if (color[nx][ny] == 0)
    {
        dfs(nx, ny);
    }
}

int main()
{
    for (int i = 0; i < MX_SZ; i++)
    {
        for (int j = 0; j < MX_SZ; j++)
        {
            dsu_p[i][j] = {i, j};
            dsu_sz[i][j] = 1;
            dist[i][j] = -1;
        }
    }
    ios_base::sync_with_stdio(false);
    freopen("robots.in", "r", stdin);
    freopen("robots.out", "w", stdout);
    int g;
    cin >> n >> m >> g;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> a[i][j];
            if (a[i][j] >= 'A' and a[i][j] <= 'Z')
            {
                rob[i][j] = true;
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (color[i][j] == 0)
            {
                was.clear();
                v0 = {i, j};
                dfs(i, j);
                crcl++;
            }
        }
    }
    /*
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cout << dist[i][j] << " ";
        }
        cout << endl;
    }
    */
    int ans = 0;
    vector<pair<pair<int, int>, int>> res;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (rob[i][j])
            {
                pair<int, int> pr = dsu_get({i, j});
                if (dsu_sz[pr.first][pr.second] != 0)
                {
                    dsu_sz[pr.first][pr.second]--;
                    dsu_tm[pr.first][pr.second]++;
                    if (g == 1)
                    {
                        res.push_back({{i, j}, BG + dsu_tm[pr.first][pr.second] - dist[i][j]});
                    }
                    ans++;
                }
            }
        }
    }
    cout << ans << '\n';
    if (g == 1)
    {
        for (int i = 0; i < (int)res.size(); i++)
        {
            cout << res[i].first.first + 1 << " " << res[i].first.second + 1 << " " << res[i].second << '\n';
        }
    }
}
