#include <bits/stdc++.h>

using namespace std;

#define forn(i, n) for(int i = 0; i < n; i++)
#define sz(a) int(a.size())
#define re return
#define fi first
#define se second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int n, m, nu = 0, g, use[1001][1001], num[1001][1001], rst[1001][1001], nu2[1001][1001];
pair<int, int> pr[1001][1001], num1[1001][1001];
vector<vector<pii> > q;
vector<vector<pair<int, pii> > > qp;
vector<pair<pii, int> > ans1;
vector<int> kk;
string s[1001];

void dfs(int x, int y, int k) {
    if (use[x][y] == 2) {
        kk[num[x][y] - 1] += k;
        re;
    }
    if (use[x][y] == 1) {
        nu++;
        num[x][y] = nu;
        kk.push_back(k);
        q.push_back({});
        qp.push_back({});
        int xx = x, yy = y, k22 = 0;
        while (true) {
            q[nu - 1].push_back({xx, yy});
            rst[xx][yy] = 0;
            nu2[xx][yy] = k22;
            k22++;
            num1[xx][yy] = {xx, yy};
            pii k2 = pr[xx][yy];
            xx = k2.fi;
            yy = k2.se;
            if (xx == x && yy == y) break;
        }
        re;
    }
    if (s[x][y] >= 'A' && s[x][y] <= 'Z') k++;
    use[x][y] = 1;
    if (s[x][y] == 's' || s[x][y] == 'S') {
        pr[x + 1][y] = {x, y};
        dfs(x + 1, y, k);
        num[x][y] = num[x + 1][y];
        if (rst[x][y] == -1) {
            rst[x][y] = 1 + rst[x + 1][y];
            num1[x][y] = num1[x + 1][y];
        }
    }
    if (s[x][y] == 'e' || s[x][y] == 'E') {
        pr[x][y + 1] = {x, y};
        dfs(x, y + 1, k);
        num[x][y] = num[x][y + 1];
        if (rst[x][y] == -1) {
            rst[x][y] = 1 + rst[x][y + 1];
            num1[x][y] = num1[x][y + 1];
        }
    }
    if (s[x][y] == 'n' || s[x][y] == 'N') {
        pr[x - 1][y] = {x, y};
        dfs(x - 1, y, k);
        num[x][y] = num[x - 1][y];
        if (rst[x][y] == -1) {
            rst[x][y] = 1 + rst[x - 1][y];
            num1[x][y] = num1[x - 1][y];
        }
    }
    if (s[x][y] == 'w' || s[x][y] == 'W') {
        pr[x][y - 1] = {x, y};
        dfs(x, y - 1, k);
        num[x][y] = num[x][y - 1];
        if (rst[x][y] == -1) {
            rst[x][y] = 1 + rst[x][y - 1];
            num1[x][y] = num1[x][y - 1];
        }
    }
    if (s[x][y] >= 'A' && s[x][y] <= 'Z') qp[num[x][y] - 1].push_back({rst[x][y], {x, y}});
    use[x][y] = 2;
}

int main() {
    iostream::sync_with_stdio(0), cin.tie(0);
    freopen("robots.in", "r", stdin);
    freopen("robots.out", "w", stdout);
    cin >> n >> m >> g;
    forn(i, n) {
        cin >> s[i];
    }
    forn (i, n) {
        forn (j, m)
            rst[i][j] = -1, num1[i][j] = {-1, -1};
    }
    forn (i, n) {
        forn (j, m) {
            if (!use[i][j]) {
                dfs(i, j, 0);
            }
            //cout << num[i][j] << " ";
        }
        //cout << endl;
    }
    int ans = 0;
    forn (i, sz(q)) {
        ans += min(sz(q[i]), kk[i]);
        sort(qp[i].begin(), qp[i].end());
        vector<pair<int, int> > pos;
        forn (j, sz(q[i])) {
            //cout << q[i][j].fi << " " << q[i][j].se << " " << nu2[q[i][j].fi][q[i][j].se] << endl;
            if (s[q[i][j].fi][q[i][j].se] <= 'z' && s[q[i][j].fi][q[i][j].se] >= 'a') {
                pos.push_back(q[i][j]);
            }
        }
        int last = 1;
        forn (j, min(sz(q[i]), kk[i])) {
            pii a = qp[i][j].se;
            if (rst[a.fi][a.se] == 0) {
                ans1.push_back({qp[i][j].se, 1});
                continue;
            }
            //assert(sz(pos) > 0);
            pii b = pos[sz(pos) - 1], c = num1[a.fi][a.se];
            pos.pop_back();
            ll kk = (nu2[b.fi][b.se] - rst[a.fi][a.se] - nu2[c.fi][c.se] - 1) % sz(q[i]);
            if (kk < 0) kk += sz(q[i]);
            kk += (last / sz(q[i])) * (sz(q[i]));
            if (kk <= last) kk += sz(q[i]);
            assert(kk > last);
            if (kk == 0) kk += sz(q[i]);
            ans1.push_back({qp[i][j].se, kk});
            last = kk;
            //assert(last < 1000000000);
        }
    }
    cout << ans << "\n";
    if (g) {
        forn(i, ans)
            cout << ans1[i].fi.fi + 1 << " " << ans1[i].fi.se + 1 << " " << ans1[i].se << "\n";
    }
    re 0;
}
