#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
    REP(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}


struct Edge {
    int to, cap, cost, rev;
};

vector< vector<Edge> > G;

void add_edge(int from, int to, int cap, int cost) {
    if (from < 0 || to < 0) return;
    G[from].push_back({to, cap, cost, (int)G[to].size()});
    G[to].push_back({from, 0, -cost, (int)G[from].size()-1});
}

int dist[21000], h[21000] = {0}, prevV[21000], prevE[21000];
ll min_cost_flow(int s, int t, int f) {
    int res = 0;
    while (f > 0) {
        fill(&dist[0], &dist[0]+21000, inf); dist[s] = 0;
        priority_queue<P, vector<P>, greater<P> > Q; Q.push({0, s});
        while ( !Q.empty() ) {
            P p = Q.top(); Q.pop();
            int v = p.second;
            if (p.first > dist[v]) continue;
            for (int i = 0; i < G[v].size(); ++i) {
                Edge& e = G[v][i];
                if (e.cap > 0 && dist[v]+e.cost+h[v]-h[e.to] < dist[e.to]) {
                    dist[e.to] = dist[v]+e.cost+h[v]-h[e.to];
                    prevV[e.to] = v;
                    prevE[e.to] = i;
                    Q.push({dist[e.to], e.to});
                }
            }
        }
        for (int i = 0; i < G.size(); ++i) h[i] += dist[i];

        if (dist[t] == inf) {
            cout << "ERROR" << endl;
            exit(1);
        }

        int d = f;
        for (int v = t; v != s; v = prevV[v]) {
            d = min(d, G[prevV[v]][prevE[v]].cap);
        }
        f -= d;
        res += d * h[t];
        for (int v = t; v != s; v = prevV[v]) {
            Edge& e = G[prevV[v]][prevE[v]];
            e.cap -= d;
            G[e.to][e.rev].cap += d;
        }
    }
    return res;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n; cin >> n;
    vector< vector<int> > O(n, vector<int>(n)); cin >> O;
    vector< vector<int> > X(n, vector<int>(n)); cin >> X;
    vector<string> m(n); cin >> m;
    vector<int> row(n), col(n);
    REP(i, n) row[i] = i;
    REP(i, n) col[i] = n+i;
    int s = n*2, t = s+1;
    G.clear(); G.resize(t+1);
    REP(i, n) REP(j, n) {
        int cost = 0;
        // col
        REP(k, n) {
            char c = i == k ? 'o' : '.';
            if (m[k][j] != c) {
                cost += c == 'o' ? O[k][j] : X[k][j];
            }
        }
        // row
        REP(k, n) {
            char c = j == k ? 'o' : '.';
            if (m[i][k] != c) {
                cost += c == 'o' ? O[i][k] : X[i][k];
            }
        }
        // cout << i << " " << j << " " << cost << endl;
        add_edge(row[i], col[j], 1, cost);
    }
    REP(i, n) add_edge(s, row[i], 1, 0);
    REP(i, n) add_edge(col[i], t, 1, 0);
    int ans = min_cost_flow(s, t, n)/2;
    vector< vector<char> > am(n, vector<char>(n, '.'));
    REP(i, n) {
        EACH(e, G[i]) {
            if (i != s && e.to != t && e.to > i && e.cap == 0) {
                int y = i, x = e.to-n;
                am[y][x] = 'o';
            }
        }
    }
    map<char, string> we = {
        {'o', "write"},
        {'.', "erase"},
    };
    cout << ans << endl;
    int cnt = 0;
    REP(i, n) REP(j, n) {
        if (am[i][j] != m[i][j]) {
            ++cnt;
        }
    }
    cout << cnt << endl;
    REP(i, n) REP(j, n) {
        if (am[i][j] != m[i][j]) {
            cout << i+1 << " " << j+1 << " " << we[am[i][j]] << endl;
        }
    }
}

Measured memory_bytes: 3424