#include <bits/stdc++.h>

using namespace std;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define all(x) begin(x),end(x)

#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector <T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair <T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

template<class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;


template<typename flow_t, typename cost_t>
struct PrimalDual {
    // O(FElogV)
    struct edge {
        int to, rev;
        flow_t cap;
        cost_t cost;
        edge(int to, flow_t cap, cost_t cost, int rev) :
                to(to), cap(cap), cost(cost), rev(rev) {}
    };

    vector<vector<edge>> g;
    const int sz;
    const cost_t INF;

    PrimalDual(int V) : g(V), sz(V), INF(numeric_limits<cost_t>::max()) {}

    void add_edge(int s, int t, flow_t cap, cost_t cost) {
        g[s].emplace_back(t, cap,  cost, (int)g[t].size());
        g[t].emplace_back(s,   0, -cost, (int)g[s].size() - 1);
    }

    void dijkstra(
            vector<cost_t>& dist,
            vector<int>& prevv,
            vector<int>& preve,
            const vector<int>& potential, int s)
    {
        dist.assign(sz, INF);
        prevv.assign(sz, -1);
        preve.assign(sz, -1);
        using Pi = pair<cost_t, int>;
        priority_queue<Pi, vector<Pi>, greater<Pi>> que;
        que.emplace(0, s);
        dist[s] = 0;
        while (!que.empty()) {
            cost_t cost; int v;
            std::tie(cost, v) = que.top();
            que.pop();
            if (dist[v] < cost) continue;
            for (int i = 0; i < g[v].size(); ++i) {
                edge &e = g[v][i];
                cost_t nextCost =
                        dist[v] + e.cost + potential[v] - potential[e.to];
                if (e.cap > 0 and dist[e.to] > nextCost) {
                    dist[e.to] = nextCost;
                    prevv[e.to] = v, preve[e.to] = i;
                    que.emplace(dist[e.to], e.to);
                }
            }
        }
    }

    cost_t min_cost_flow(int s, int t, flow_t f) {
        cost_t ret = 0;
        vector<cost_t> potential(sz, 0);

        while (f > 0)
        {
            vector<cost_t> dist;
            vector<int> prevv, preve;
            dijkstra(dist, prevv, preve, potential, s);

            if (dist[t] == INF) return -1;

            for (int v = 0; v < sz; ++v) potential[v] += dist[v];

            flow_t diff = f;
            for (int v = t; v != s; v = prevv[v]) {
                diff = min(diff, g[prevv[v]][preve[v]].cap);
            }
            f -= diff;
            ret += diff * potential[t];

            for (int v = t; v != s; v = prevv[v]) {
                edge &e = g[prevv[v]][preve[v]];
                e.cap -= diff;
                g[v][e.rev].cap += diff;
            }
        }

        return ret;
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int n; cin >> n;
    vvi W(n, vi(n)), E(n, vi(n));
    REP(i, n) {
        REP(j, n) {
            cin >> W[i][j];
        }
    }
    REP(i, n) {
        REP(j, n) {
            cin >> E[i][j];
        }
    }
    vector<string> F(n);
    REP(i, n) cin >> F[i];

    PrimalDual<int,int> flow(2*n+2);

    vi row(n), col(n);
    REP(i, n) {
        REP(j, n) {
            if (F[i][j] == 'o') {
                row[i] += E[i][j];
                col[j] += E[i][j];
            }
        }
    }

    REP(i, n) {
        REP(j, n) {
            int cost = row[i] + col[j];
            if (F[i][j] == 'o') {
                cost -= 2 * E[i][j];
            } else {
                cost += 2 * W[i][j];
            }
            flow.add_edge(i, n+j, 1, cost);
        }
    }
    REP(i, n) {
        flow.add_edge(2*n, i, 1, 0);
        flow.add_edge(n+i, 2*n+1, 1, 0);
    }

    int ans = flow.min_cost_flow(2*n, 2*n+1, n);

    vi match(n, -1);
    REP(i, n) {
        for (auto& e : flow.g[i]) {
            int j = e.to - n;
            if (j < 0 or n <= j) continue;
            if (e.cap == 0) {
                match[i] = j;
                break;
            }
        }
    }

    vector<P> erase, write;
    REP(i, n) {
        REP(j, n) {
            if (F[i][j] == 'o' and match[i] != j) {
                erase.emplace_back(i+1, j+1);
            }
            if (F[i][j] == '.' and match[i] == j) {
                write.emplace_back(i+1, j+1);
            }
        }
    }

    cout << ans / 2 << endl;
    cout << erase.size() + write.size() << endl;
    for (auto& tp : erase) {
        cout << tp.first << " " << tp.second << " erase" << endl;
    }
    for (auto& tp : write) {
        cout << tp.first << " " << tp.second << " write" << endl;
    }

    return 0;
}



Measured memory_bytes: 3604