#include <bits/stdc++.h>

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;
template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
inline double distance(double y1, double x1, double y2, double x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }

const int INF = 1L << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy = { 0, 1, 0, -1 }, dx = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）

using namespace std;


class Hungarian {

public:

    vector<int> x;
    int hungarian(const vector<vector<int>> &a) {
        int n = a.size(), p, q;

        vector<int> fx(n, INF), fy(n, 0);
        vector<int> y(n, -1);
        x.resize(n, -1);
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                fx[i] = max(fx[i], a[i][j]);
            }
        }

        for (int i = 0; i < n;) {
            vector<int> t(n, -1), s(n + 1, i);
            for (p = q = 0; p <= q && x[i] < 0; ++p) {
                for (int k = s[p], j = 0; j < n && x[i] < 0; ++j) {
                    if (fx[k] + fy[j] == a[k][j] && t[j] < 0) {
                        s[++q] = y[j], t[j] = k;
                        if (s[q] < 0) {
                            for (p = j; p >= 0; j = p) {
                                y[j] = k = t[j], p = x[k], x[k] = j;
                            }
                        }
                    }
                }
            }
            if (x[i] < 0) {
                int d = INF;
                for (int k = 0; k <= q; ++k) {
                    for (int j = 0; j < n; ++j) {
                        if (t[j] < 0) {
                            d = min(d, fx[s[k]] + fy[j] - a[s[k]][j]);
                        }
                    }
                }
                for (int j = 0; j < n; ++j) {
                    fy[j] += (t[j] < 0 ? 0 : d);
                }
                for (int k = 0; k <= q; ++k) {
                    fx[s[k]] -= d;
                }
            } else {
                ++i;
            }
        }

        int ret = 0;
        for (int i = 0; i < n; ++i) {
            ret += a[i][x[i]];
        }
        return ret;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;
    VV<int> add(N, V<int>(N)), del(N, V<int>(N)), field(N, V<int>(N));
    FOR(i, 0, N) {
        FOR(j, 0, N) {
            cin >> add[i][j];
        }
    }
    FOR(i, 0, N) {
        FOR(j, 0, N) {
            cin >> del[i][j];
        }
    }

    int ans = 0;
    VV<int> cost(N, V<int>(N));
    FOR(i, 0, N) {
        string s;
        cin >> s;
        FOR(j, 0, N) {
            field[i][j] = (s[j] == 'o') ? 1 : 0;

            // 全部消す
            if (field[i][j] == 1) {
                ans -= del[i][j];
                cost[i][j] += del[i][j];
            }
            else {
                cost[i][j] = -add[i][j];
            }
        }
    }

    Hungarian hg;
    print(-(ans + hg.hungarian(cost)));

    VV<int> field2(N, V<int>(N, 0));
    V<string> a;
    FOR(y, 0, N) {
        FOR(x, 0, N) {
            bool m = (hg.x[y] == x);
            if (m and field[y][x] == 1 or not m and field[y][x] == 0) { continue; }

            if (field[y][x] == 1) {
                a.emplace_back(to_string(y + 1) + " " + to_string(x + 1) + " erase");
            }
            else {
                a.emplace_back(to_string(y + 1) + " " + to_string(x + 1) + " write");
            }
        }
    }

    print(a.size());
    FOE(s, a) {
        print(s);
    }
    return 0;
}
