#include <bits/stdc++.h>

using namespace std;

#define next dfogjofdiofgj

const int maxn = 1000;

int n, m, g;
char is_robot[maxn][maxn];
pair<int, int> next[maxn][maxn];

char used[maxn][maxn];
int dist[maxn][maxn];
pair<int, int> root[maxn][maxn];
int cnt[maxn][maxn];
int len[maxn][maxn];
vector< pair<int, int> > vertex[maxn][maxn];

void dfs(int x, int y, int &px, int &py, int d=0) {
    if (used[x][y]) {
        if (root[x][y].first == -1) {
            px = x; py = y;
            len[px][py] = d - dist[px][py];
        } else {
            tie(px, py) = root[x][y];
        }
        return;
    }
    used[x][y] = true;
    dist[x][y] = d;
    int nx, ny;
    tie(nx, ny) = next[x][y];
    dfs(nx, ny, px, py, d + 1);
}

void dfs2(int x, int y, int px, int py) {
    if (root[x][y].first != -1) return;
    root[x][y] = {px, py};
    if (is_robot[x][y]) cnt[px][py]++;
    int nx, ny;
    tie(nx, ny) = next[x][y];
    dfs2(nx, ny, px, py);
}

void dfs3(int x, int y, int px, int py) {
    if (dist[x][y] != -1) return;
    if (x == px && y == py) {
        dist[x][y] = 0;
        if (is_robot[px][py]) vertex[px][py].push_back({x, y});
        return;
    }
    int nx, ny;
    tie(nx, ny) = next[x][y];
    if (dist[nx][ny] == -1) {
        dfs3(nx, ny, px, py);
    }
    dist[x][y] = dist[nx][ny] + 1;
    if (is_robot[x][y]) vertex[px][py].push_back({x, y});
}

bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
    int x1, y1, x2, y2;
    tie(x1, y1) = a;
    tie(x2, y2) = b;
    return dist[x1][y1] < dist[x2][y2];
}

void recovery(int px, int py, int &time) {
    vector< pair<int, int> > &v = vertex[px][py];
    sort(v.begin(), v.end(), cmp);
    int prev;
    int nxt = time;
    for (int i = 0; i < min(len[px][py], (int) v.size()); i++) {
        int x, y;
        tie(x, y) = v[i];
        int d = dist[x][y];
        if (i == 0) {
            cout << x + 1 << ' ' << y + 1 << ' ' << time << '\n';
            prev = time + d;
        } else {
            int tmp = prev - d + 1;
            while (tmp < time) tmp += len[px][py];
            cout << x + 1 << ' ' << y + 1 << ' ' << tmp << '\n';
            prev = tmp + d;
        }
        nxt = max(nxt, prev);
    }
    time = nxt + 5;
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    freopen("robots.in", "r", stdin);
    freopen("robots.out", "w", stdout);

    cin >> n >> m >> g;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < m; j++) {
            if ('A' <= s[j] && s[j] <= 'Z') {
                is_robot[i][j] = true;
                s[j] += 'a' - 'A';
            }
            if (s[j] == 'n') next[i][j] = {i - 1, j};
            else if (s[j] == 's') next[i][j] = {i + 1, j};
            else if (s[j] == 'e') next[i][j] = {i, j + 1};
            else if (s[j] == 'w') next[i][j] = {i, j - 1};
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            root[i][j] = {-1, -1};
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            int px, py;
            dfs(i, j, px, py);
            dfs2(i, j, px, py);
        }
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            ans += min(len[i][j], cnt[i][j]);
        }
    }

    cout << ans << '\n';
    if (g == 0) return 0;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            dist[i][j] = -1;
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            dfs3(i, j, root[i][j].first, root[i][j].second);
        }
    }

    int time = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (!vertex[i][j].empty()) {
                recovery(i, j, time);
                /*cerr << ' ' << i << ' ' << j << endl;
                for (auto it: vertex[i][j]) {
                    cerr << it.first << ' ' << it.second << endl;
                }*/
            }
        }
    }

}

