#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }



struct Edge {
    int rev, from, to, cap, icap, cost;
    Edge(int r, int f, int t, int ca, int co) : rev(r), from(f), to(t), cap(ca), icap(ca), cost(co) {}
    friend ostream& operator << (ostream& s, const Edge& E) {
        if (E.cap > 0) return s << E.from << "->" << E.to << '(' << E.cap << ',' << E.cost << ')';
        else return s;
    }
};

const int MAX_V = 1000;
const int INF = 1<<29;

struct Graph {
    int V;
    vector<Edge> list[MAX_V];
    
    Graph(int n = 0) : V(n) {for (int i = 0; i < MAX_V; ++i) list[i].clear();}
    void init(int n = 0) {V = n; for (int i = 0; i < MAX_V; ++i) list[i].clear();}
	void resize(int n = 0) {V = n;}
    void reset() {for (int i = 0; i < V; ++i) for (int j = 0; j < list[i].size(); ++j) list[i][j].cap = list[i][j].icap;}
    inline vector<Edge>& operator [] (int i) {return list[i];}
    
    Edge &redge(Edge e) {
        if (e.from != e.to) return list[e.to][e.rev];
        else return list[e.to][e.rev+1];
    }
    
    void addedge(int from, int to, int cap, int cost) {
        list[from].push_back(Edge(list[to].size(), from, to, cap, cost));
        list[to].push_back(Edge(list[from].size()-1, to, from, 0, -cost));
    }
    
    void addbiedge(int from, int to, int cap, int cost) {
        list[from].push_back(Edge(list[to].size(), from, to, cap, cost));
        list[to].push_back(Edge(list[from].size()-1, to, from, cap, cost));
    }
    
    friend ostream& operator << (ostream& s, const Graph& G) {
        for (int i = 0; i < G.V; ++i) {s << i << " : " << G.list[i];}
        return s;
    }
};

Graph G;

int pot[MAX_V];
int dist[MAX_V];
int prevv[MAX_V];
int preve[MAX_V];

int MinCost(Graph &G, int s, int t, int f) {
    int res = 0;
    fill(pot, pot+G.V, 0);
    while (f > 0) {
        priority_queue<pair<int,int>, vector<pair<int,int> >, greater<pair<int,int> > > que; 
        fill(dist, dist+G.V, INF);
        dist[s] = 0;
        que.push(make_pair(0,s));
        while(!que.empty()) {
            pair<int,int> p = que.top();
            que.pop();
            int v = p.second;
            if (dist[v] < p.first) continue;
            for (int i = 0; i < G[v].size(); ++i) {
                Edge &e = G[v][i];
                if (e.cap > 0 && dist[e.to] > dist[v] + e.cost + pot[v] - pot[e.to]) {
                    dist[e.to] = dist[v] + e.cost + pot[v] - pot[e.to];
                    prevv[e.to] = v;
                    preve[e.to] = i;
                    que.push(make_pair(dist[e.to], e.to));
                }
            }
        }
        
        if (dist[t] == INF) return -1;
        
        for (int v = 0; v < G.V; ++v) pot[v] += dist[v];
        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 * pot[t];
        for (int v = t; v != s; v = prevv[v]) {
            Edge &e = G[prevv[v]][preve[v]];
            Edge &re = G.redge(e);
            e.cap -= d;
            re.cap += d;
        }
    }
    return res;
}


int n;
int W[150][150], E[150][150];
string S[150];

int main() {
    while (cin >> n) {
        for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) cin >> W[i][j];
        for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) cin >> E[i][j];
        for (int i = 0; i < n; ++i) cin >> S[i];
        
        G.init(2*n+2);
        int s = 2*n, t = 2*n+1;
        
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                
                int tot = 0;
                for (int k = 0; k < n; ++k) {
                    if (k == j) {
                        if (S[i][k] == '.') tot += W[i][k];
                    }
                    else {
                        if (S[i][k] == 'o') tot += E[i][k];
                    }
                }
                
                G.addedge(i, n+j, 1, tot);
            }
        }
        for (int i = 0; i < n; ++i) {
            G.addedge(s, i, 1, 0);
            G.addedge(n+i, t, 1, 0);
        }
        
        int res = MinCost(G, s, t, n);
        
        vector<pair<pint,string> > ans;
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                if (S[i][j] == '.' && G[i][j].cap == 0) ans.PB(MP(pint(i,j), "write"));
                if (S[i][j] == 'o' && G[i][j].cap == 1) ans.PB(MP(pint(i,j), "erase"));
            }
        }
        
        cout << res << endl;
        cout << ans.size() << endl;
        for (int i = 0; i < ans.size(); ++i) {
            cout << ans[i].first.first+1 << " " << ans[i].first.second+1 << " " << ans[i].second << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 2160