#include <bits/stdc++.h>

#define x first
#define y second

using namespace std;

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

typedef pair<int, int> pint;

struct robo
{
    int x, y;
    int cn;
    int len;
    pint par;
    robo(int cn = -1, int len = 0) : cn(cn), len(len) {}
    bool operator < (const robo &o)
    {
        return len < o.len;
    }
};

vector<vector<int> > f;

pint go(pint a)
{
    int x = a.x;
    int y = a.y;
    return pint(x + dx[f[x][y]], y + dy[f[x][y]]);
}

int main()
{
    ifstream cin("robots.in");
    ofstream cout("robots.out");
    int n, m, g;
    cin >> n >> m >> g;
    f.resize(n, vector<int>(m));
    vector<vector<pint> > cy;
    vector<vector<vector<robo> > > par(n, vector<vector<robo> > (m));
    vector<vector<bool> > is_r(n, vector<bool> (m, 0));
    vector<vector<robo> > arr(n, vector<robo>(m));
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
        {
            arr[i][j].x = i;
            arr[i][j].y = j;
            char c;
            cin >> c;
            if (c >= 'A' && c <= 'Z')
            {
                is_r[i][j] = 1;
                c = c - 'A' + 'a';
            }
            int x;
            if (c == 's')
                x = 0;
            if (c == 'e')
                x = 1;
            if (c == 'n')
                x = 2;
            if (c == 'w')
                x = 3;
            f[i][j] = x;
        }
    cerr << "readed\n";
    vector<pair<pint, int> > out;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            if (arr[i][j].cn == -1)
            {
                int ccn = cy.size();
                pint p(i, j);
                vector<pint> w;
                while(arr[p.x][p.y].cn == -1)
                {
                    arr[p.x][p.y].cn = ccn;
                    w.push_back(p);
                    p = go(p);
                }
                if (arr[p.x][p.y].cn == ccn)
                {
                    int bi;
                    for (bi = 0; w[bi] != p; bi++);
                    for (int i = 0; i < bi; i++)
                    {
                        arr[w[i].x][w[i].y].par = p;
                        arr[w[i].x][w[i].y].len = bi - i;
                        if (is_r[w[i].x][w[i].y])
                            par[p.x][p.y].push_back(arr[w[i].x][w[i].y]);
                    }
                    vector<pint> tnc;
                    for (int i = bi; i < w.size(); i++)
                    {
                        tnc.push_back(w[i]);
                        arr[w[i].x][w[i].y].par = w[i];
                        arr[w[i].x][w[i].y].len = 0;
                    }
                    cy.push_back(tnc);
                }
                else
                {
                    int bi = arr[p.x][p.y].len;
                    p = arr[p.x][p.y].par;
                    for (int i = 0; i < w.size(); i++)
                    {
                        arr[w[i].x][w[i].y].par = p;
                        arr[w[i].x][w[i].y].cn = arr[p.x][p.y].cn;
                        arr[w[i].x][w[i].y].len = bi + w.size() - i;
                        if (is_r[w[i].x][w[i].y])
                            par[p.x][p.y].push_back(arr[w[i].x][w[i].y]);
                    }
                }
            }
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            sort(par[i][j].begin(), par[i][j].end());
    int mt = 0;
    for (auto &c : cy)
    {
        int time = 0;
        int cnt = 0;
        for (auto &e : c) if (cnt < c.size())
        {
            if (is_r[e.x][e.y])
            {
                cnt++;
                out.push_back(make_pair(pint(e.x, e.y), time));
            }
            else
                time++;
        }
        time = c.size();
        for (auto &e : c)
        {
            for (robo i : par[e.x][e.y]) if (cnt < c.size())
            {
                time++;
                cnt++;
                mt = min(mt, time - i.len);
                out.push_back(make_pair(pint(i.x, i.y), time - i.len));
            }
            else
                break;
            time++;
        }
    }
    cout << out.size() << "\n";
    if (g == 1)
        for (auto s : out)
            cout << s.x.x + 1 << " " << s.x.y + 1 << " " << s.y + mt + 1<< "\n";
    return 0;
}
