#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2429>
 問題文============================================================
 =================================================================
 解説=============================================================
 
 ================================================================
 */

#define MAX_V 500
struct edge{
    int to;
    int cap;
    int cost;
    int rev;
    edge(){}
    edge(int to,int cap,int cost,int rev):to(to),cap(cap),cost(cost),rev(rev){}
};

int V;
vector<edge> G[MAX_V];
int dist[MAX_V];
int prevv[MAX_V],preve[MAX_V];

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

int min_cost_flow(int s,int t,int f){
    int res=0;
    while(f>0){
        fill(dist,dist+V,INF);
        dist[s]=0;
        bool update = true;
        while(update){
            update = false;
            for(int v=0; v<V ;v++){
                if(dist[v]==INF) 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) {
                        dist[e.to] = dist[v] + e.cost;
                        prevv[e.to] = v;
                        preve[e.to] = i;
                        update = true;
                    }
                }
            }
        }
        if(dist[t]==INF) return -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*dist[t];
        for(int v=t; v!=s; v=prevv[v]){
            edge &e = G[prevv[v]][preve[v]];
            e.cap -= d;
            G[v][e.rev].cap += d;
        }
    }
    return res;
}

void solve(){
    int n; cin >> n;
    vector<vector<int>> W(n,vector<int>(n));
    vector<vector<int>> E(n,vector<int>(n));
    vector<vector<char>> F(n,vector<char>(n));
    for(auto& vec:W)for(auto& in:vec) cin >> in;
    for(auto& vec:E)for(auto& in:vec) cin >> in;
    for(auto& vec:F)for(auto& in:vec) cin >> in;
    
    int Sum = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n;j++){
            if(F[i][j] == 'o') Sum += E[i][j];
        }
    }
    
    
    V = 2*n+2;
    int S = 2*n, T = 2*n+1;
    for(int i = 0; i < n;i++){
        add_edge(S,i,1,0);
        add_edge(i+n,T,1,0);
    }
    
    for(int i = 0; i < n;i++){
        for(int j = 0; j < n;j++){
            if(F[i][j] == 'o'){
                add_edge(i,j+n,1,-E[i][j]);
            }else{
                add_edge(i,j+n,1,W[i][j]);
            }
        }
    }
    
    cout << Sum + min_cost_flow(S,T,n) << endl;
    using Items = tuple<int,int,string>;
    queue<Items> q;
    for(int i = 0; i < n;i++){
        for(auto& e : G[i]){
            if(e.to == S || e.to == T) continue;
            if(e.cap == 0){
                if(F[i][e.to-n] == '.'){
                    q.push(Items(i,e.to-n,"write"));
                }
            }else{
                if(F[i][e.to-n] == 'o'){
                    q.push(Items(i,e.to-n,"erase"));
                }
            }
        }
    }
    cout << q.size() << endl;
    while(q.size()){
        int i,j; string query;
        tie(i,j,query) = q.front(); q.pop();
        cout << i+1 << " " << j+1 << " " << query << endl;
    }
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve();
    return 0;
}



Measured memory_bytes: 3636