#include <bits/stdc++.h>

#define whole(xs) (xs).begin(),(xs).end()

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    const int INF = INT_MAX / 2;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    struct Edge {
        int from, to, cap, cost;
        Edge* rev;
        Edge(int from, int to, int cap, int cost) : from(from), to(to), cap(cap), cost(cost) {}
    };
    vector<vector<Edge*>> G;

    void addEdge(int from, int to, int cap, int cost) {
        assert(from != to);
        Edge* e = new Edge(from, to, cap, cost);
        Edge* r = new Edge(to, from, 0, -cost);
        e->rev = r;
        r->rev = e;
        G[from].push_back(e);
        G[to].push_back(r);
    }

    int minCostFlow(int s, int t, int f) {
        const int N = G.size();
        int ret = 0;
        vector<Edge*> prev(N, nullptr);
        while (f > 0) {
            // Bellman Ford
            vector<int> D(N, INF);
            D[s] = 0;
            bool updated = true;
            while (updated) {
                updated = false;
                for (int v = 0; v < N; v++) {
                    if (D[v] == INF) continue;
                    for (auto e : G[v]) {
                        if (e->cap == 0) continue;
                        int ncost = D[v] + e->cost;
                        if (D[e->to] > ncost) {
                            D[e->to] = ncost;
                            prev[e->to] = e;
                            updated = true;
                        }
                    }
                }
            }

            if (D[t] == INF) return -1; // ?°???¶?????¶????????????????????????s?????????t??????????????¨?????????????????????????????±?????????
            int d = f;
            for (Edge* p = prev[t]; p != nullptr; p = prev[p->from]) {
                d = min(d, p->cap);
            }

            f -= d;
            ret += d * D[t];
            for (Edge* p = prev[t]; p != nullptr; p = prev[p->from]) {
                p->cap -= d;
                p->rev->cap += d;
            }
        }
        return ret;
    }
    

    int N;
    vector<vector<int>> W, E;
    vector<string> F;

    void input() {
        cin >> N;
        W.resize(N, vector<int>(N, 0)); cin >> W;
        E.resize(N, vector<int>(N, 0)); cin >> E;
        F.resize(N); cin >> F;
    }

    void solve() {
        G.clear(); G.resize(2 + 2 * N);
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                int cost = 0;
                for (int k = 0; k < N; k++) {
                    if (F[i][k] == 'o') {
                        cost += (j == k ? 0 : E[i][k]);
                    } else {
                        cost += (j == k ? W[i][k] : 0);
                    }
                }
                addEdge(1 + i, 1 + N + j, 1, cost);
            }
            addEdge(0, 1 + i, 1, 0);
            addEdge(1 + N + i, 1 + 2 * N, 1, 0);
        }
        cout << minCostFlow(0, 1 + 2 * N, N) << endl;

        vector<string> X(N, string(N, '.'));
        for (int i = 1; i <= N; i++) {
            for (auto e : G[i]) {
                if (e->cap == 0) {
                    if (e->to <= N || e->to > 2*N) continue;
                    X[e->from - 1][e->to - (N + 1)] = 'o';
                }
            }
        }
        int c = 0;
        ostringstream os;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (F[i][j] == X[i][j]) continue;
                c++;
                os << i + 1 << " " << j + 1 << " " << (F[i][j] == 'o' ? "erase" : "write") << endl;
            }
        }
        cout << c << endl;
        cout << os.str() << endl;
    }
}

int main() {
    input(); solve();
    return 0;
}

Measured memory_bytes: 4232