#include <bits/stdc++.h>0

using namespace std;

#define forn(i, n) for (int i = 0; i < n; i++)
#define sqr(a) ((a) * (a))
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define sz(a) (a.size())
#define all(a) a.begin(), a.end()
#define NAME "robots"
#define FREOPEN freopen(NAME".in", "r", stdin); freopen(NAME".out", "w", stdout);

typedef long long ll;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;

const int INF = 2e9;
const ll INF64 = 9e18;
const int N = 1000100;
const int M = 1010;

int ans, nn, n, m, flag, g[N];
bool cyc[N];
int mark[N], cc[N], ok[N], kk = 0, color[N], rob[N], rast[N];
string s[M];
stack < int > st;
vector < int > top;
vector < pair < pii, int > > tt;
vector < int > c[N];
vector < pii > ver[N];
vector < int > gg[N];
bool ff;

pii f(int q)
{
    int xx = q / m;
    if (q % m == 0)
    {
        return mp(xx, m);
    }
    xx++;
    int yy = q - (xx - 1) * m;
    return mp(xx, yy);
}

void dfs_cycle(int v)
{
    if (ff)
        return;
    mark[v] = 1;
    st.push(v);
    int u = g[v];
    if (mark[u] == 1)
    {
        kk++;
        ff = 1;
        while (!st.empty())
        {
            int uu = st.top();
            color[uu] = kk;
            cc[kk]++;
            c[kk].pb(uu);
            mark[uu] = 2;
            st.pop();
            if (uu == u)
                break;
        }
        reverse(all(c[kk]));
        return;
    }
    else
        if (!mark[u])
            dfs_cycle(u);
    if (ff)
        return;
    st.pop();
    mark[v] = 2;
}

void dfs_top(int v)
{
    mark[v] = 1;
    int u = g[v];
    if (!mark[u])
        dfs_top(u);
    top.pb(v);
}

void dfs(int v, int h, int k)
{
    mark[v] = 1;
    ver[k].pb(mp(h, v));
   // cout << "============    " << f(v).x << ' ' << f(v).y << ' ' << h << endl;
    forn(i, sz(gg[v]))
        {
            int u = gg[v][i];
            if (!mark[u])
                dfs(u, h + 1, k);
        }
}



int main()
{
    //FREOPEN;
    // 64          97
    cin >> n >> m >> flag;
    nn = n * m;
    for (int i = 1; i <= n; i++)
    {
        cin >> s[i];
        s[i] = " " + s[i];
        for (int j = 1; j <= m; j++)
        {
            int q = (i - 1) * m + j;
            if (s[i][j] < 97)
            {
                rob[q] = 1;
                s[i][j] += 32;
            }
            if (s[i][j] == 'n')
            {
                int qq = (i - 2) * m + j;
                g[q] = qq;
                gg[qq].pb(q);
            }
            if (s[i][j] == 's')
            {
                int qq = i * m + j;
                g[q] = qq;
                gg[qq].pb(q);
            }
            if (s[i][j] == 'w')
            {
                int qq = (i - 1) * m + j - 1;
                g[q] = qq;
                gg[qq].pb(q);
            }
            if (s[i][j] == 'e')
            {
                int qq = (i - 1) * m + j + 1;
                g[q] = qq;
                gg[qq].pb(q);
            }
        }
    }
    for (int i = 1; i <= nn; i++)
        if (!mark[i])
        {
            while (!st.empty())
            {
                mark[st.top()] = 2;
                st.pop();
            }
            ff = 0;
            dfs_cycle(i);
        }

    for (int i = 1; i <= nn; i++)
        mark[i] = 0;
    for (int i = 1; i <= nn; i++)
        if (!mark[i])
            dfs_top(i);
    reverse(all(top));
    //=======================
    forn(i, nn)
    {
        int v = top[i];
        int u = g[v];
        if (color[v])
        {
            ok[color[v]] += rob[v];
            rob[v] = 0;
        }
        else
        {
            if (color[u])
            {
                ok[color[u]] += rob[v];
                rob[v] = 0;
            }
            else
                rob[u] += rob[v];
            rob[v] = 0;
        }
    }
    for (int i = 1; i <= nn; i++)
        mark[i] = 0;
    for (int v = 1; v <= kk; v++)
    {
        forn(i, sz(c[v]))
        {
            int u = c[v][i];
            mark[u] = 1;
        }
        forn(i, sz(c[v]))
        {
            int u = c[v][i];
            dfs(u, 0, u);
            sort(all(ver[u]));
        }
        int timer = 1000100;
        int q = sz(c[v]);
        forn(i, sz(c[v]))
        {
            timer++;
            int u = c[v][i];
            forn(j, sz(ver[u]))
            {
                if (q == 0)
                    break;
                int vv = ver[u][j].y;
                tt.pb(mp(f(vv), timer - ver[u][j].x));
                q--;
            }

        }
    }


    for (int i = 1; i <= kk; i++)
        ans += min(ok[i], cc[i]);
    cout << ans << endl;
    if (flag)
    forn(i, sz(tt))
    {
        printf("%d %d %d\n", tt[i].x.x, tt[i].x.y, tt[i].y);




    }



    return 0;
}


/*

3 4 0
SSSS
EESW
ENWW


3 4 1
SSSS
EeSW
ENwW


4 4 1
essS
Eess
Snww
EeWN





*/
